import ‘package:flutter/material.dart’;
class Home extends StatefulWidget {
const Home({ Key? key }) : super(key: key);
@override
State createState() => _HomeState();
}
class _HomeState extends State {
Map? data = {};
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
final Map data = ModalRoute.of(context)!.settings.arguments as Map;
print(data);
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 120, 0, 0),
child: Column(
children: [
TextButton.icon(
onPressed: () {
Navigator.pushNamed(context,'/location');
},
icon: const Icon(Icons.edit_location),
label: const Text('Edit Location'),
),
const SizedBox(height: 20,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
data['location'],
style: const TextStyle(
fontSize: 20.0,
letterSpacing: 2,
),
)
],
),
const SizedBox(height: 20,),
Text(
data['time'],
style: const TextStyle(
fontSize: 66,
),
),
],
),
),
),
);
}
}
{location: Berlin, flag: germany.jpg, time: 9:08 AM}
2
Answers
try with
By this Null safety operator you are telling the returned value could be null as well. Once the value is received handle the null value as per your requirement.
you have to replace Map with a custom class,
you have to pass arguments at pushNamed function
you have also to place appBar:AppBar() in Scaffold for back Button
it can be empty