I am creating a multi-paged app on flutter to To determine the time based on the location, but when the code is turned on, there's a problem on this page, I tried to fix the problem, but the error still exists" type 'Null' is not a subtype of type 'bool'" I'll include the other pages in the comments.
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
)
),
],
),
),
),
),
);
}
}