如何避免登陆页面转向颤抖

问题描述 投票:1回答:1

以下代码是main.dart

import 'package:flutter/material.dart';
import 'landing page.dart';


    void main() {
      runApp(new MaterialApp(
        home: LandingPages(),
      ));
    }

这是我的登陆页面类:

import 'package:flutter/material.dart';
import 'package:listview/devices.dart';
import 'main.dart';

class LandingPages extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Is there anybody out there?',
      home: new Scaffold(
          body: new Stack(
            children: <Widget>[
              new Container(
                decoration: new BoxDecoration(
                  image: new DecorationImage(
                      image: new AssetImage( 'images/landing.png'),
                      fit: BoxFit.cover
                  ),
                ),
              ),
              new InkWell(
                onTap: () =>print(Navigator.of(context).push(new MaterialPageRoute(builder:(BuildContext)=>MyApp()))),

              )

            ],
          )
      ),
    );
  }
}

我的第二页,我可以轻松返回登录页面:

import 'package:flutter/material.dart';
import 'package:listview/devicepage.dart';

void main(){
  runApp(new MaterialApp(
    home: new MyApp(),
  ));
}
class MyApp extends StatefulWidget{
  @override
  _State createState() =>new _State();

}
class _State extends State<MyApp>{

  List<bool> _data =new List<bool>();


  @override

  void initState() {
    setState(() {
      for (int i=0;i<10;i++){
        _data.add(false);
      }
    });
  }
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar:new AppBar(
        title: new Text("خانه هوشمند"),
      ),
      body: new ListView.builder(
        itemCount: _data.length,
        itemBuilder: (BuildContext,int index){
          return   new Card(
            child: new Column(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[

                new Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: <Widget>[
                    new Image.asset(
                      'images/acc.png',
                      height: 100.0,
                      fit: BoxFit.contain,
                    ),
                  ],
                ),

                const ListTile(

                  title: const Text('نام دستگاه',textAlign: TextAlign.left,),
                  subtitle: const Text('آخرین وضعیت موجود',textAlign: TextAlign.left,),
                ),
                new ButtonTheme.bar( // make buttons use the appropriate styles for cards
                  child: new ButtonBar(
                    children: <Widget>[
                      new FlatButton(
                        child: const Text('بیشتر'),
                        onPressed: () { Navigator.push(context,MaterialPageRoute(builder: (context)=> DevicePage())); },
                      ),

                    ],
                  ),
                ),
              ],
            ),
          );


        },
      ),
    );
  }
}

我的第二页没有后退按钮,但是当我在手机中使用后退按钮时,它会转回来有人能告诉我如何解决我的问题吗?

flutter
1个回答
1
投票

在着陆页中使用Navigator.pushReplacement()而不是push

© www.soinside.com 2019 - 2024. All rights reserved.