gpt4 book ai didi

flutter - 类型 'Null' 不是类型转换中类型 'Map' 的子类型

转载 作者:行者123 更新时间:2023-12-05 02:00:27 25 4
gpt4 key购买 nike

当我想创建包含多个页面的动态导航时出现此错误。这是下面的代码..

import 'package:flutter/material.dart';
import 'screens/locations/locations.dart';
import 'screens/location_detail.dart';

const LocationsRoute = "/";
const LocationDetailRout = '/location_detail';

class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
onGenerateRoute: _routes(),
);

 RouteFactory _routes() {
return (settings) {
// final Map<String, dynamic> arguments = settings.arguments;
final arguments = settings.arguments as Map<String, dynamic>;
Widget screen;
switch (settings.name) {
case LocationsRoute:
screen = Locations();
break;
case LocationDetailRout:
screen = LocationDetail(arguments['id']);
}
};

最佳答案

快速修复

Map arguments = (settings.arguments??{}) as Map;

关于flutter - 类型 'Null' 不是类型转换中类型 'Map<String, dynamic>' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67376299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com