Created
January 22, 2021 11:46
-
-
Save DanielRomanMartinez/f13ca924e567674d872dc45662483941 to your computer and use it in GitHub Desktop.
How to return data when back to previous activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: MyWidget(), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold ( | |
body: Column( | |
children: [ | |
ElevatedButton( | |
onPressed: () async { | |
String textFromPageB = await Navigator.push( | |
context, | |
MaterialPageRoute( | |
builder: (_) => PageB(), | |
)); | |
print(textFromPageB); | |
}, | |
child: Text('Go to Page B'), | |
), | |
] | |
) | |
); | |
} | |
} | |
class PageB extends StatelessWidget { | |
@override | |
Widget build(BuildContext context){ | |
return ElevatedButton( | |
onPressed: () async { | |
Navigator.pop(context, "My Message"); | |
}, | |
child: Text('Go back'), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment