Created
August 28, 2020 16:44
-
-
Save ibtesam123/dfa05b0aae8d7127e37797dc8951735a to your computer and use it in GitHub Desktop.
This file contains hidden or 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'; | |
import 'package:test_proj/nextpage.dart'; | |
class HomePage extends StatefulWidget { | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
TextEditingController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = TextEditingController(); | |
} | |
Widget _buildBody() { | |
return Center( | |
child: Column( | |
mainAxisSize: MainAxisSize.min, | |
children: [ | |
Container( | |
width: 200, | |
child: TextField( | |
controller: controller, | |
), | |
), | |
SizedBox(height: 15), | |
RaisedButton( | |
onPressed: () async { | |
final res = await Navigator.of(context).push( | |
MaterialPageRoute( | |
builder: (context) { | |
return NextPage(controller: controller); | |
}, | |
), | |
); | |
setState(() { | |
controller = res; | |
}); | |
}, | |
child: Text('Next page'), | |
) | |
], | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: _buildBody(), | |
); | |
} | |
} |
This file contains hidden or 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'; | |
import 'package:test_proj/homepage.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: HomePage(), | |
); | |
} | |
} |
This file contains hidden or 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'; | |
class NextPage extends StatefulWidget { | |
final TextEditingController controller; | |
NextPage({@required this.controller}); | |
@override | |
_NextPageState createState() => _NextPageState(); | |
} | |
class _NextPageState extends State<NextPage> { | |
Widget _buildBody() { | |
return Center( | |
child: RaisedButton( | |
onPressed: () { | |
widget.controller.text = 'This is the new text'; | |
Navigator.of(context).pop(widget.controller); | |
}, | |
child: Text('Pop'), | |
), | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: _buildBody(), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment