异常找不到路由震荡的生成器

时间:2019-11-19 16:51:55

标签: flutter routes

我是扑扑的新手,有人可以帮我解决这个问题吗?我想尝试一下,但当我想切换路线时出现一些异常 主要代码:

void main() => runApp(MaterialApp(
  initialRoute:'/home',
  routes: {
    '/':(context) => Loading(),
    '/home':(context) => Home(),
    '/loc':(context) => ChooseLocation(),
}
));

我的主页代码

import 'package:flutter/material.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
          child: Column(
            children: <Widget>[
              FlatButton.icon(
                onPressed: () {
                  Navigator.pushNamed(context,'/loc');
                },
                icon: Icon(Icons.edit_location),
                label: Text('Edit Location'))
        ],
      )),
    );
  }
}

遇到这样的错误

Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following assertion was thrown while handling a gesture:
Could not find a generator for route RouteSettings("/loc", null) in the _WidgetsAppState.

有人可以帮我吗!

2 个答案:

答案 0 :(得分:0)

“热重启”解决了我的问题:)

答案 1 :(得分:-1)

要解决此问题,我们应该尝试使用抖动热重启