multichildlayoutparentdata不是flexparentdata类型的子类型导航器布局问题

时间:2018-10-10 04:31:31

标签: flutter flutter-layout

class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context){
return new MaterialApp( home: new HomeScreen(), );
}}

class HomeScreen extends StatefulWidget{
HomeScreenState createState() => HomeScreenState();
}
//CLASS STATE
class HomeScreenState extends State<HomeScreen>{
Choice _selectedChoice = choices[0]; // The app's "state".

  void _select(Choice choice) {
    // Causes the app to rebuild with the new _selectedChoice.
    if (choice.title=='1'){
    Navigator.push(context,MaterialPageRoute(builder:(context)=>SecondScreen()),);}
    setState(() {

      _selectedChoice = choice;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: AppBar(
          title: const Text('TEST APP'),
          actions: <Widget>[
            // action button
            IconButton(
              icon: Icon(choices[0].icon),
              onPressed: () {
                _select(choices[0]);
              },
            ),
            // action button
            IconButton(
              icon: Icon(choices[1].icon),
              onPressed: () {
                _select(choices[1]);
              },
            ),
            // overflow menu
            PopupMenuButton<Choice>(
              onSelected: _select,
              itemBuilder: (BuildContext context) {
                return choices.skip(2).map((Choice choice) {
                  return PopupMenuItem<Choice>(
                    value: choice,
                    child: Text(choice.title),
                  );
                }).toList();
              },
            ),
          ],
        ),
        body: Expanded(
         child: ChoiceCard(choice: _selectedChoice),
        )
      );
  } //build
} //class State

该代码摘自Flutter教程BasicAppSample。

我试图添加代码以按一些按钮后转到下一个屏幕 使用Navigator push。

是什么原因导致此运行时错误?我已经成功编译,但是得到了 “ MultiChildLayoutParentData”类型不是“ FlexParentData”类型的子类型

以及有关如何解决此问题的任何想法?

我希望这可以帮助解决相同主题的某些问题。将做更多的研究并将其发布在这里。

谢谢。

0 个答案:

没有答案