Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:font_awesome_flutter/font_awesome_flutter.dart';
- import 'dart:async';
- import 'dart:convert' as convert;
- import 'package:login/dashboard.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:http/http.dart' as http;
- void main() => runApp(new MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return new MaterialApp(
- theme: new ThemeData(primarySwatch: Colors.blue),
- home: new LoginPage(),
- routes: <String,WidgetBuilder>{
- '/AdminPage': (BuildContext context)=> new Dashboard(),
- '/LoginPage': (BuildContext context)=> new LoginPage(),
- },
- );
- }
- }
- class LoginPage extends StatefulWidget {
- @override
- State createState() => new LoginPageState();
- }
- class LoginPageState extends State<LoginPage>
- with SingleTickerProviderStateMixin {
- Animation<double> _iconAnimation;
- AnimationController _iconAnimationController;
- TextEditingController email=new TextEditingController();
- TextEditingController pass=new TextEditingController();
- String msg='';
- Future<List> _login() async {
- SharedPreferences prefs =await SharedPreferences.getInstance();
- final response =await http.post('http://192.168.43.64/temanbelajar/login.php', body: {
- "email": email.text,
- "password": pass.text,
- });
- // var datauser=json.decode(response.body);
- var jsonResponse = convert.jsonDecode(response.body);
- if (response.statusCode == 200) {
- var success = jsonResponse['success'];
- var data = jsonResponse['login'][0] ;
- if(success=='1'){
- setState(() {
- prefs.setInt('id', data['login']['id']);
- prefs.setString('name', data['login']['nama']);
- });
- Navigator.pushReplacementNamed(context, '/AdminPage');
- }
- print("test= $success.");
- print("test= $data.");
- } else {
- print("Request failed with status: ${response.statusCode}.");
- }
- return jsonResponse;
- }
- @override
- void initState() {
- super.initState();
- _iconAnimationController = new AnimationController(
- vsync: this, duration: new Duration(milliseconds: 500));
- _iconAnimation = new CurvedAnimation(
- parent: _iconAnimationController,
- curve: Curves.bounceOut,
- );
- _iconAnimation.addListener(() => this.setState(() {}));
- _iconAnimationController.forward();
- }
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- backgroundColor: Colors.white,
- body: new Stack(fit: StackFit.expand, children: <Widget>[
- new Image(
- image: new AssetImage("assets/girl.jpeg"),
- fit: BoxFit.cover,
- colorBlendMode: BlendMode.darken,
- color: Colors.black87,
- ),
- new Theme(
- data: new ThemeData(
- brightness: Brightness.dark,
- inputDecorationTheme: new InputDecorationTheme(
- // hintStyle: new TextStyle(color: Colors.blue, fontSize: 20.0),
- labelStyle:
- new TextStyle(color: Colors.tealAccent, fontSize: 25.0),
- )),
- isMaterialAppTheme: true,
- child: new Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new FlutterLogo(
- size: _iconAnimation.value * 140.0,
- ),
- new Container(
- padding: const EdgeInsets.all(40.0),
- child: new Form(
- autovalidate: true,
- child: new Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- new TextFormField(
- controller: email,
- decoration: new InputDecoration(
- labelText: "Enter Email", fillColor: Colors.white),
- keyboardType: TextInputType.emailAddress,
- ),
- new TextFormField(
- controller: pass,
- decoration: new InputDecoration(
- labelText: "Enter Password",
- ),
- obscureText: true,
- keyboardType: TextInputType.text,
- ),
- new Padding(
- padding: const EdgeInsets.only(top: 60.0),
- ),
- new MaterialButton(
- height: 50.0,
- minWidth: 150.0,
- color: Colors.green,
- splashColor: Colors.teal,
- textColor: Colors.white,
- child: new Icon(FontAwesomeIcons.signInAlt),
- onPressed: () {
- _login();
- },
- )
- ],
- ),
- ),
- )
- ],
- ),
- ),
- ]),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement