Flutter布局异常问题

2,120 阅读1分钟

目录

1.flutter No material widget found textfield widgets require a material widget ancestor

2.'!_debugLocked': is not true.

1.flutter No material widget found textfield widgets require a material widget ancestor

使用 Scaffold 包裹就好

Widget LoginPage() {
   return new Scaffold(body: *your whole code*)
}

2.'!_debugLocked': is not true.

在使用Navigator.pushAndRemoveUntil 时报出的问题

@optionalTypeArgs
  static Future<T> pushAndRemoveUntil<T extends Object>(BuildContext context, Route<T> newRoute, RoutePredicate predicate) {
    return Navigator.of(context).pushAndRemoveUntil<T>(newRoute, predicate);
  }

解决方案 predicate要设置(我的情况是,若不设置,第二次调用时就出问题)

1.设置路由

class MyApp extends StatelessWidget { 
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      routes: {
        "/welcome":(BuildContext context) => WelcomePage(),
      },
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primaryColor: ColorDef.colorPrimary),
      home: WelcomePage(
        fromLogin: false,
      ),
    );
  }
}

2.使用方法

 Navigator.pushAndRemoveUntil(
          context,
          new MaterialPageRoute(builder: (context) => new LoginPage()),
          ModalRoute.withName("/welcome"));