【发布时间】:2022-01-26 08:02:10
【问题描述】:
// ignore_for_file: prefer_const_constructors
import 'package:flutter/material.dart';
import 'package:world_time/pages/loading.dart';
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
Map data = {};
@override
Widget build(BuildContext context) {
final data = ModalRoute.of(context)?.settings.arguments;
return Scaffold(
body: SafeArea(
child: Column(
children: [
TextButton.icon(
onPressed: () {
Navigator.pushNamed(context, '/choose_location');
},
label: Text("Edit location"),
icon: Icon(Icons.edit_location_alt_sharp),
),
// ERROR
Text(data['location']), // The method '[]' can't be unconditionally invoked because the
receiver can be 'null'.
Try making the call conditional (using '?.') or adding a
null check to the target ('!')
],
)),
);
}
}
【问题讨论】: