Last active
May 17, 2020 09:37
-
-
Save prasadsunny1/f842e69d9e7ba9718a3bd97ef6ee92df to your computer and use it in GitHub Desktop.
Take an input from user
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'; | |
void main() { | |
runApp(MaterialApp( | |
home: Page1(), | |
)); | |
} | |
class Page1 extends StatelessWidget { | |
TextEditingController usernameController = TextEditingController(); | |
TextEditingController passwordController = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Page 1"), | |
), | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
TextField( | |
controller: usernameController, | |
decoration: InputDecoration( | |
labelText: "Username", | |
hintText: "Your Username", | |
), | |
), | |
TextField( | |
controller: passwordController, | |
obscureText: true, | |
obscuringCharacter: '*', | |
decoration: InputDecoration( | |
labelText: "Password", | |
hintText: "Your password", | |
), | |
), | |
RaisedButton( | |
child: Text("Go to page 2"), | |
onPressed: () { | |
Navigator.of(context).push( | |
MaterialPageRoute( | |
builder: (context) { | |
return Page2(); | |
}, | |
), | |
); | |
}, | |
) | |
], | |
), | |
), | |
), | |
); | |
} | |
} | |
class Page2 extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Page 2"), | |
), | |
body: Center( | |
child: Container( | |
child: Column( | |
children: [ | |
RaisedButton( | |
child: Text("Go Back"), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}) | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment