Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:usmdemo/secondscreen.dart';
- import 'user.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(title: 'Material App',
- home: Scaffold(
- appBar: AppBar(title: Text('Login'),),
- body: MyHome(),
- ),
- );
- }
- }
- class MyHome extends StatefulWidget {
- //functions
- @override
- _MyHomeState createState() => _MyHomeState();
- }
- class _MyHomeState extends State<MyHome> {
- void clickandPrint() {
- print('Dah Click');
- print('Dah Click');
- }
- TextEditingController _controllerName = TextEditingController();
- TextEditingController _controllerPassword = TextEditingController();
- @override
- Widget build(BuildContext context) {
- return Container(
- color: Colors.yellow[50],
- margin: EdgeInsets.all(30),
- padding: EdgeInsets.all(30),
- child: Column(
- children: <Widget>[
- Text('Nama:', style: TextStyle(
- fontSize: 30
- ),),
- TextField(controller: _controllerName,),
- Text('Password:', style: TextStyle(
- fontSize: 30
- ),),
- TextField(
- controller: _controllerPassword,
- obscureText: true,
- ),
- SizedBox(height: 50,),
- RaisedButton(
- child: Text('Login', style: TextStyle(
- fontSize: 30
- ),),
- onPressed: () {
- //code
- print(_controllerName.text);
- print(_controllerPassword.text);
- //declare Object yg nak passing ke Screen2
- User objectPass;
- objectPass.name = _controllerName.text;
- objectPass.password = _controllerPassword.text;
- //Screen2 ada "post" terima objectPass
- Navigator.push(context, MaterialPageRoute(builder:(context)
- => Screen2(objectReceived: objectPass)) );
- },
- ),
- ],
- ),
- );
- }
- }
- //Alert
- /*
- showDialog(context: context, builder: (BuildContext context) {
- return AlertDialog(
- title: Text("AlertDialog"),
- content: Text("Creates an alert dialog."),
- actions: <Widget>[
- RaisedButton(
- color: Colors.green,
- child: Text("Open"),
- onPressed: () {
- clickandPrint();
- Navigator.of(context).pop();
- },
- ),
- RaisedButton(
- color: Colors.orange,
- child: Text("Close"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- ),
- ],
- );
- }
- );
- */
- //Snackbar
- /*
- child: Center(
- child: RaisedButton(
- child: Text('Save Data'),
- onPressed: () {
- final snackBar = SnackBar(
- backgroundColor: Colors.pink,
- content: Text('Berjaya Save Data ke DB'),
- action: SnackBarAction(
- label: 'Print', textColor: Colors.yellowAccent,
- onPressed: () {
- clickandPrint();
- },
- ),
- );
- Scaffold.of(context).showSnackBar(snackBar);
- },
- ),
- ),
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement