Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:usmdemo/secondscreen.dart';
  3. import 'user.dart';
  4.  
  5. void main() => runApp(MyApp());
  6.  
  7. class MyApp extends StatelessWidget {
  8.  
  9.  
  10. @override
  11. Widget build(BuildContext context) {
  12. return MaterialApp(title: 'Material App',
  13. home: Scaffold(
  14. appBar: AppBar(title: Text('Login'),),
  15. body: MyHome(),
  16. ),
  17. );
  18. }
  19. }
  20.  
  21. class MyHome extends StatefulWidget {
  22. //functions
  23. @override
  24. _MyHomeState createState() => _MyHomeState();
  25. }
  26.  
  27. class _MyHomeState extends State<MyHome> {
  28. void clickandPrint() {
  29. print('Dah Click');
  30. print('Dah Click');
  31. }
  32.  
  33. TextEditingController _controllerName = TextEditingController();
  34.  
  35. TextEditingController _controllerPassword = TextEditingController();
  36.  
  37. @override
  38. Widget build(BuildContext context) {
  39. return Container(
  40. color: Colors.yellow[50],
  41. margin: EdgeInsets.all(30),
  42. padding: EdgeInsets.all(30),
  43. child: Column(
  44. children: <Widget>[
  45. Text('Nama:', style: TextStyle(
  46. fontSize: 30
  47. ),),
  48. TextField(controller: _controllerName,),
  49. Text('Password:', style: TextStyle(
  50. fontSize: 30
  51. ),),
  52. TextField(
  53. controller: _controllerPassword,
  54. obscureText: true,
  55. ),
  56. SizedBox(height: 50,),
  57. RaisedButton(
  58. child: Text('Login', style: TextStyle(
  59. fontSize: 30
  60. ),),
  61. onPressed: () {
  62. //code
  63. print(_controllerName.text);
  64. print(_controllerPassword.text);
  65.  
  66. //declare Object yg nak passing ke Screen2
  67. User objectPass;
  68. objectPass.name = _controllerName.text;
  69. objectPass.password = _controllerPassword.text;
  70.  
  71. //Screen2 ada "post" terima objectPass
  72. Navigator.push(context, MaterialPageRoute(builder:(context)
  73. => Screen2(objectReceived: objectPass)) );
  74.  
  75. },
  76. ),
  77. ],
  78. ),
  79. );
  80. }
  81. }
  82.  
  83.  
  84. //Alert
  85. /*
  86. showDialog(context: context, builder: (BuildContext context) {
  87. return AlertDialog(
  88. title: Text("AlertDialog"),
  89. content: Text("Creates an alert dialog."),
  90. actions: <Widget>[
  91. RaisedButton(
  92. color: Colors.green,
  93. child: Text("Open"),
  94. onPressed: () {
  95. clickandPrint();
  96. Navigator.of(context).pop();
  97. },
  98. ),
  99. RaisedButton(
  100. color: Colors.orange,
  101. child: Text("Close"),
  102. onPressed: () {
  103. Navigator.of(context).pop();
  104. },
  105. ),
  106. ],
  107. );
  108. }
  109. );
  110. */
  111.  
  112.  
  113. //Snackbar
  114. /*
  115. child: Center(
  116. child: RaisedButton(
  117. child: Text('Save Data'),
  118. onPressed: () {
  119. final snackBar = SnackBar(
  120. backgroundColor: Colors.pink,
  121.  
  122. content: Text('Berjaya Save Data ke DB'),
  123. action: SnackBarAction(
  124. label: 'Print', textColor: Colors.yellowAccent,
  125. onPressed: () {
  126. clickandPrint();
  127. },
  128. ),
  129. );
  130. Scaffold.of(context).showSnackBar(snackBar);
  131. },
  132. ),
  133. ),
  134. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement