Advertisement
amarel

cobalogin

Mar 9th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.15 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:font_awesome_flutter/font_awesome_flutter.dart';
  3. import 'dart:async';
  4. import 'dart:convert' as convert;
  5. import 'package:login/dashboard.dart';
  6. import 'package:shared_preferences/shared_preferences.dart';
  7. import 'package:http/http.dart' as http;
  8.  
  9. void main() => runApp(new MyApp());
  10.  
  11. class MyApp extends StatelessWidget {
  12. @override
  13. Widget build(BuildContext context) {
  14. return new MaterialApp(
  15. theme: new ThemeData(primarySwatch: Colors.blue),
  16. home: new LoginPage(),
  17. routes: <String,WidgetBuilder>{
  18. '/AdminPage': (BuildContext context)=> new Dashboard(),
  19. '/LoginPage': (BuildContext context)=> new LoginPage(),
  20. },
  21. );
  22. }
  23. }
  24.  
  25. class LoginPage extends StatefulWidget {
  26. @override
  27. State createState() => new LoginPageState();
  28. }
  29.  
  30. class LoginPageState extends State<LoginPage>
  31. with SingleTickerProviderStateMixin {
  32. Animation<double> _iconAnimation;
  33. AnimationController _iconAnimationController;
  34.  
  35. TextEditingController email=new TextEditingController();
  36. TextEditingController pass=new TextEditingController();
  37.  
  38. String msg='';
  39.  
  40. Future<List> _login() async {
  41. SharedPreferences prefs =await SharedPreferences.getInstance();
  42. final response =await http.post('http://192.168.43.64/temanbelajar/login.php', body: {
  43. "email": email.text,
  44. "password": pass.text,
  45. });
  46.  
  47. // var datauser=json.decode(response.body);
  48. var jsonResponse = convert.jsonDecode(response.body);
  49. if (response.statusCode == 200) {
  50. var success = jsonResponse['success'];
  51. var data = jsonResponse['login'][0] ;
  52. if(success=='1'){
  53. setState(() {
  54. prefs.setInt('id', data['login']['id']);
  55. prefs.setString('name', data['login']['nama']);
  56. });
  57. Navigator.pushReplacementNamed(context, '/AdminPage');
  58.  
  59. }
  60.  
  61. print("test= $success.");
  62. print("test= $data.");
  63. } else {
  64. print("Request failed with status: ${response.statusCode}.");
  65. }
  66. return jsonResponse;
  67. }
  68.  
  69.  
  70.  
  71. @override
  72. void initState() {
  73. super.initState();
  74. _iconAnimationController = new AnimationController(
  75. vsync: this, duration: new Duration(milliseconds: 500));
  76. _iconAnimation = new CurvedAnimation(
  77. parent: _iconAnimationController,
  78. curve: Curves.bounceOut,
  79. );
  80. _iconAnimation.addListener(() => this.setState(() {}));
  81. _iconAnimationController.forward();
  82. }
  83.  
  84. @override
  85. Widget build(BuildContext context) {
  86.  
  87. return new Scaffold(
  88. backgroundColor: Colors.white,
  89. body: new Stack(fit: StackFit.expand, children: <Widget>[
  90. new Image(
  91. image: new AssetImage("assets/girl.jpeg"),
  92. fit: BoxFit.cover,
  93. colorBlendMode: BlendMode.darken,
  94. color: Colors.black87,
  95. ),
  96. new Theme(
  97. data: new ThemeData(
  98. brightness: Brightness.dark,
  99. inputDecorationTheme: new InputDecorationTheme(
  100. // hintStyle: new TextStyle(color: Colors.blue, fontSize: 20.0),
  101. labelStyle:
  102. new TextStyle(color: Colors.tealAccent, fontSize: 25.0),
  103. )),
  104. isMaterialAppTheme: true,
  105. child: new Column(
  106. mainAxisAlignment: MainAxisAlignment.center,
  107. children: <Widget>[
  108. new FlutterLogo(
  109. size: _iconAnimation.value * 140.0,
  110. ),
  111. new Container(
  112. padding: const EdgeInsets.all(40.0),
  113. child: new Form(
  114. autovalidate: true,
  115. child: new Column(
  116. mainAxisAlignment: MainAxisAlignment.start,
  117. children: <Widget>[
  118. new TextFormField(
  119. controller: email,
  120. decoration: new InputDecoration(
  121. labelText: "Enter Email", fillColor: Colors.white),
  122. keyboardType: TextInputType.emailAddress,
  123. ),
  124. new TextFormField(
  125. controller: pass,
  126. decoration: new InputDecoration(
  127. labelText: "Enter Password",
  128. ),
  129. obscureText: true,
  130. keyboardType: TextInputType.text,
  131. ),
  132. new Padding(
  133. padding: const EdgeInsets.only(top: 60.0),
  134. ),
  135. new MaterialButton(
  136. height: 50.0,
  137. minWidth: 150.0,
  138. color: Colors.green,
  139. splashColor: Colors.teal,
  140. textColor: Colors.white,
  141. child: new Icon(FontAwesomeIcons.signInAlt),
  142. onPressed: () {
  143. _login();
  144. },
  145. )
  146. ],
  147. ),
  148. ),
  149. )
  150. ],
  151. ),
  152. ),
  153. ]),
  154. );
  155. }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement