我在flutter上创建了一个多页app来根据位置来判断时间,但是开启代码的时候,这个页面有问题,我尝试修复问题,但是错误依然存在"type' Null' 不是 'bool' 类型的子类型”我将在评论中包含其他页面。
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
Map? data={};
@override
Widget build(BuildContext context) {
if (data!= null) {
data = ModalRoute.of(context)!.settings.arguments as Map?;}
// set background image
final String? bgImage = data?['isDayTime'] ? 'day.png' : 'night.png';
final Color? bgColor = data?['isDayTime'] ? Colors.blue : Colors.indigo[700];
return Scaffold(
backgroundColor: bgColor,
body: SafeArea(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/$bgImage'),
fit: BoxFit.cover,
)
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 120.0, 0, 0),
child: Column(
children: <Widget>[
FlatButton.icon(
onPressed: () async {
dynamic result = await Navigator.pushNamed(context, '/location');
if(result != null){
setState(() {
data = {
'Time': result['Time'],
'Location': result['Location'],
'isDayTime': result['isDayTime'],
'Flag': result['Flag']
};
});
}
},
icon: Icon(
Icons.edit_location,
color: Colors.grey[300],
),
label: Text(
'Edit Location',
style: TextStyle(
color: Colors.grey[300],
),
),
),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
data?['Location'],
style: TextStyle(
fontSize: 28.0,
letterSpacing: 2.0,
color: Colors.white,
),
),
],
),
SizedBox(height: 20.0),
Text(
data?['Time'],
style: TextStyle(
fontSize: 66.0,
color: Colors.white
)
),
],
),
),
),
),
);
}
}