Flutter 颤振-屏幕拖动的边缘无意中返回页面

Flutter 颤振-屏幕拖动的边缘无意中返回页面,flutter,dart,Flutter,Dart,我一直在使用材料通过颤振来设计我的应用程序。一不小心,我在屏幕边缘刷了一下,它又回到了一个页面,回到了一个不该走的路线。这在整个应用程序中都是一致的,Cupertino软件包不在任何地方使用 在决定转到登录视图(如果已注销)或主页(已登录)之前,应用程序会启动一个自定义启动屏幕 如果登录,刷回总是返回到启动屏幕,因为它是前一条路线,应用程序崩溃 第1页 @override Widget build(BuildContext context) { return _loading =

我一直在使用材料通过颤振来设计我的应用程序。一不小心,我在屏幕边缘刷了一下,它又回到了一个页面,回到了一个不该走的路线。这在整个应用程序中都是一致的,Cupertino软件包不在任何地方使用

在决定转到登录视图(如果已注销)或主页(已登录)之前,应用程序会启动一个自定义启动屏幕

如果登录,刷回总是返回到启动屏幕,因为它是前一条路线,应用程序崩溃

第1页

  @override
  Widget build(BuildContext context) {
    return _loading == false
        ? Scaffold(
            backgroundColor: Colors.white,
            appBar: _buildBar(context),
            body: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisSize: MainAxisSize.min,
                        children: <Widget>[
                          Text(
                            'test',
                            style: TextStyle(
                                fontWeight: FontWeight.bold, fontSize: 18),
                          ),
                          SizedBox(height: 10),
                          ButtonTheme(
                              minWidth: MediaQuery.of(context).size.width / 2,
                              height: 40,
                              child: RaisedButton(
                                textColor: Colors.white,
                                color: prefix0.backgroundColor,
                                child: Text("View"),
                                onPressed: () => Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) => PDFView(
                                              document: link,
                                            ))),
                                shape: new RoundedRectangleBorder(
                                  borderRadius: new BorderRadius.circular(15.0),
                                ),
                              )),
                        ],
                      ),  
            resizeToAvoidBottomPadding: false,
          )
        : Center(child: CircularProgressIndicator());
  }
}

@覆盖
小部件构建(构建上下文){
返回_loading==false
?脚手架(
背景颜色:Colors.white,
appBar:_buildBar(上下文),
正文:专栏(
crossAxisAlignment:crossAxisAlignment.start,
mainAxisSize:mainAxisSize.min,
儿童:[
正文(
"测试",,
样式:TextStyle(
fontWeight:fontWeight.bold,fontSize:18),
),
尺寸箱(高度:10),
钮扣(
minWidth:MediaQuery.of(context).size.width/2,
身高:40,
孩子:升起按钮(
textColor:Colors.white,
颜色:prefix0.backgroundColor,
子项:文本(“视图”),
按下:()=>Navigator.push(
上下文
材料路线(
生成器:(上下文)=>PDFView(
文件:链接,
))),
形状:新的RoundedRectangleBorder(
边界半径:新边界半径。圆形(15.0),
),
)),
],
),  
resizeToAvoidBottomPadding:false,
)
:居中(子项:循环压缩机指示器());
}
}
第2页


class PDFView extends StatefulWidget {
  final String document;
  final File file;

  PDFView({this.document, this.file});
  @override
  _PDFViewState createState() => _PDFViewState();
}

class _PDFViewState extends State<PDFView> {
  bool _isLoading = true;

  Widget _buildBar(BuildContext context) {
    return new AppBar(
      backgroundColor: prefix0.backgroundColor,
      centerTitle: true,
      title: Text('PDF View'),
      actions: <Widget>[
        FlatButton(
          child: Icon(
            Icons.share,
            color: Colors.white,
          ),
          onPressed: () {
            // Share.share('${widget.document}');
          },
        ),
      ],
    );
  }

  PDFDocument doc;

  @override
  void initState() {
    super.initState();
    _getData();
  }

  _getData() async {
    if (widget.document != null) {
      doc = await PDFDocument.fromURL(widget.document);
      setState(() {
        _isLoading = false;
      });
    } else if (widget.file != null) {
      doc = await PDFDocument.fromFile(widget.file);
      setState(() {
        _isLoading = false;
      });
    } else {

      doc = await PDFDocument.fromURL(
          'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf');
      setState(() {
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: _buildBar(context),
      body: Center(
          child: _isLoading
              ? Center(child: CircularProgressIndicator())
              : PDFViewer(
                  document: doc,
                  showPicker: false,
                )),
    );
  }
}

类PDFView扩展了StatefulWidget{
最终字符串文件;
最终文件;
PDFView({this.document,this.file});
@凌驾
_PDFViewState createState()=>PDFViewState();
}
类_PDFViewState扩展状态{
bool_isLoading=true;
小部件构建栏(构建上下文){
返回新的AppBar(
backgroundColor:prefix0.backgroundColor,
标题:对,
标题:文本(“PDF视图”),
行动:[
扁平按钮(
子:图标(
Icons.share,
颜色:颜色,白色,
),
已按下:(){
//Share.Share('${widget.document}');
},
),
],
);
}
PDF文件文件;
@凌驾
void initState(){
super.initState();
_getData();
}
_getData()异步{
如果(widget.document!=null){
doc=wait PDFDocument.fromURL(widget.document);
设置状态(){
_isLoading=false;
});
}else if(widget.file!=null){
doc=wait PDFDocument.fromFile(widget.file);
设置状态(){
_isLoading=false;
});
}否则{
doc=wait PDFDocument.fromURL(
'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf');
设置状态(){
_isLoading=false;
});
}
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:_buildBar(上下文),
正文:中(
子项:_正在加载
?中心(子项:循环压缩机指示器())
:PDFViewer(
文件:doc,,
选秀者:错,
)),
);
}
}

为我在编辑文件时的拙劣尝试“黑色混乱”道歉

我怎样才能防止这些刷回

寻找解决方案的可能发展:

添加
WillPopScope(
onWillPop:(){
返回Future.value(false);

},脚手架上方的
会阻止滑动。但是,它也会禁用“后退”按钮。因此,滑动操作仅在视图为“可移动”时可用``

这是iOS上Material package的默认行为,iPhone用户希望在应用程序中的任何地方都能看到这种行为。但是,如果您不想让用户在登录后立即返回某个特定屏幕,如登录屏幕,那么您应该使用
pushReplacement
,而不是只使用
push
但是,如果您想在任何情况下都这样做,请看一看

请提供您的代码和应用程序屏幕截图,让其他人了解您的问题。我添加了一些代码和图像,以显示正在拖动的屏幕。您可以在不想使用滑动(登录页面)返回该页面时使用pushReplacement。它将用路由堆栈中新页的索引替换旧页的索引