Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何使用Dart解决颤振应用程序中的路线错误?_Flutter_Dart_Routes - Fatal编程技术网

Flutter 如何使用Dart解决颤振应用程序中的路线错误?

Flutter 如何使用Dart解决颤振应用程序中的路线错误?,flutter,dart,routes,Flutter,Dart,Routes,我正在开发一个以Dart为后端语言的颤振应用程序。尝试使用(context.namedRoote()的导航器在页面中导航时 我收到一条错误消息 在_WidgetsAppState中找不到路由设置(“/item category”,{id:vegets,title:vegets})的生成器。 我已经在每个小部件中完成了必要的导入,但代码中没有提到 我的main.dart文件是: void main() { runApp(MyApp()); } class MyApp extends Sta

我正在开发一个以Dart为后端语言的颤振应用程序。尝试使用(context.namedRoote()的导航器在页面中导航时
我收到一条错误消息
在_WidgetsAppState中找不到路由设置(“/item category”,{id:vegets,title:vegets})的生成器。
我已经在每个小部件中完成了必要的导入,但代码中没有提到


我的main.dart文件是:
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Grow Eat Food',
      theme: ThemeData(
        primarySwatch: Colors.green,
        visualDensity: VisualDensity.adaptivePlatformDensity,
        fontFamily: 'Raleway',
      ),
      initialRoute: '/', // default is '/'
      routes: {
        '/': (ctx) => MyHomePage(),
        EachItemDetailScreen.routeName: (ctx) => EachItemDetailScreen(),
        ItemListScreen.routeName: (ctx) => ItemListScreen(),
        Settings.routeName: (ctx) => Settings(),
        Profile.routeName: (ctx) => Profile(),
        Listings.routeName: (ctx) => Listings(),
      },
    );
  }
}
显示项目屏幕的屏幕位于ItemListScreen类中,代码如下:

class ItemListScreen extends StatefulWidget {
  static const routeName = '/item-list';

  @override
  _ItemListScreenState createState() => _ItemListScreenState();
}

class _ItemListScreenState extends State<ItemListScreen> {
  @override
  Widget build(BuildContext context) {
    final routeArgs =
        ModalRoute.of(context).settings.arguments as Map<String, String>;
    final categoryTitle = routeArgs['title'];
    final categoryId = routeArgs['id'];
    final categoryItems = ITEMS_DATA.where((item) {
      return item.categories.contains(categoryId);
    }).toList();
    return Scaffold(
      appBar: AppBar(
        title: Text(categoryTitle),
      ),
      body: ListView.builder(
        itemBuilder: (ctx, index) {
          return EachItem(
            id: categoryItems[index].id,
            title: categoryItems[index].title,            
          );
        },
        itemCount: categoryItems.length,
      ),
    );
  }
}

ItemListScreen.routeName:(ctx)=>ItemListScreen(),

对不起,我没有得到你的答案
enum Condition {
  Fresh,
  Frozen,
  Immediate_sale,
}

enum Status {
  Available,
  Pending,
  Sold,
}

class Item {
  final String id;
  final List<String> categories;
  final String title;
  final String imageUrl;
  final double price;
  final String priceType;
  // final DateTime harvestDate;
  final Condition condition;
  final Status status;
  final bool isOrganic;
  final Map location;

  const Item({
    @required this.id,
    @required this.categories,
    // may be more than one category
    @required this.title,
    @required this.imageUrl,
    @required this.price,
    @required this.priceType,
    // eg.per kg/per 12/per 100
    // @required this.harvestDate,
    @required this.condition,
    // fresh/frozen/should go immediately
    @required this.status,
    // sold/pending/available
    @required this.location,
    @required this.isOrganic,
  });
}
class EachItem extends StatelessWidget {
  final String id;
  final String title;
  /*final String imageUrl;
  final double price;
  final String priceType;
  // final DateTime harvestDate;
  final Condition condition;
  final Status status;
  final bool isOrganic;*/

  EachItem({
    @required this.id,
    // may be more than one category
    @required this.title,
    /*@required this.imageUrl,
    @required this.price,
    @required this.priceType,
    // eg.per kg/per 12/per 100
    // @required this.harvestDate,
    @required this.condition,
    // fresh/frozen/should go immediately
    @required this.status,
    // sold/pending/available
    @required this.isOrganic,*/
  });

  void selectItem(BuildContext context) {
    Navigator.of(context).pushNamed(
      ItemListScreen.routeName,
      arguments: id,
    );
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => selectItem(context),
      child: Card(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(5),
        ),
        elevation: 4,
        margin: EdgeInsets.all(10),
        child: Column(
          children: <Widget>[
            Stack(
              children: <Widget>[
                Positioned(
                  bottom: 20,
                  right: 10,
                  child: Container(
                    width: 300,
                    color: Colors.black54,
                    padding: EdgeInsets.symmetric(
                      vertical: 5,
                      horizontal: 20,
                    ),
                    child: Text(
                      title,
                      style: TextStyle(
                        fontSize: 26,
                        color: Colors.white,
                      ),
                      softWrap: true,
                      overflow: TextOverflow.fade,
                    ),
                  ),
                )
              ],
            ),                
          ],
        ),
      ),
    );
  }
}
const ITEMS_DATA = const [
  Item(
    id: '1',
    title: 'Apple',
    categories: ['Fruits'],
    price: 3.5,
    priceType: 'per kg',
    // harvestDate: DateTime.parse('2012-02-27 13:27:00'),
    condition: Condition.Fresh,
    status: Status.Available,
    isOrganic: true,
    location: null,
    imageUrl:
        'https://cdn.pixabay.com/photo/2018/04/09/18/26/asparagus-3304997_1280.jpg',
  ),
];