Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:SAKTI.Link/Login/ResetAkun/reset-akun.dart';
- import 'package:SAKTI.Link/home/menu-tab.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_spinkit/flutter_spinkit.dart';
- import 'package:global_configuration/global_configuration.dart';
- import 'package:http/http.dart' as http;
- import 'package:shared_preferences/shared_preferences.dart';
- class Loginpage extends StatefulWidget {
- static String tag = 'login-page';
- @override
- _LoginPageState createState() => _LoginPageState();
- }
- class SlideRightRoute extends PageRouteBuilder {
- final Widget page;
- SlideRightRoute({this.page})
- : super(
- pageBuilder: (
- BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- ) =>
- page,
- transitionsBuilder: (
- BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- Widget child,
- ) =>
- SlideTransition(
- position: Tween<Offset>(
- begin: const Offset(1, 0),
- end: Offset.zero,
- ).animate(animation),
- child: child,
- ),
- );
- }
- class SlideLeftRoute extends PageRouteBuilder {
- final Widget page;
- SlideLeftRoute({this.page})
- : super(
- pageBuilder: (
- BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- ) =>
- page,
- transitionsBuilder: (
- BuildContext context,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- Widget child,
- ) =>
- SlideTransition(
- position: Tween<Offset>(
- begin: const Offset(-1, 0),
- end: Offset.zero,
- ).animate(animation),
- child: child,
- ),
- );
- }
- class _LoginPageState extends State<Loginpage> {
- TextEditingController hpController = TextEditingController();
- TextEditingController sandiController = TextEditingController();
- TextEditingController usernameController = TextEditingController();
- TextEditingController passwordController = TextEditingController();
- String _tokenfcm = '';
- String version = '';
- String slImgSplash = '';
- String slKoperasi = '';
- String slUrl = '';
- String slUrlSplash = '';
- String slHp = '';
- String slFingerprint = '';
- String slSimid = '';
- String slToken = '';
- String slTokenKey = '';
- String nama = '';
- String noAnggota = '';
- String generateQR = '';
- String tipeReset = '';
- String img = "";
- String koperasi = '';
- bool _obscureText = false;
- void showLoading() {
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return AlertDialog(
- elevation: 0,
- backgroundColor: Colors.transparent,
- content: SpinKitThreeBounce(color: Colors.white, size: 35.0));
- });
- }
- getLocalStorage() async {
- final prefs = await SharedPreferences.getInstance();
- setState(() {
- koperasi = prefs.getString('koperasi') != null
- ? prefs.getString('koperasi')
- : "";
- img = prefs.getString('img');
- });
- }
- void initState() {
- super.initState();
- getLocalStorage();
- }
- void login() async {
- showLoading();
- final prefs = await SharedPreferences.getInstance();
- var body = {
- 'hp': usernameController.text,
- 'version': version,
- 'tokenfcm': _tokenfcm,
- };
- var url =
- GlobalConfiguration().getString("sl_urlSKK") + "api/saktilink/getURL";
- http
- .post(
- url,
- body: body,
- )
- .then((response) {
- Navigator.of(context).pop();
- var res = json.decode(response.body);
- if (res['status']['response'] == 200) {
- setState(() {
- slImgSplash = res['data']['img_splash'];
- slKoperasi = res['data']['koperasi'];
- slUrl = res['data']['url'];
- slUrlSplash = res['data']['url_splash'];
- prefs.setString('img_splash', slImgSplash);
- prefs.setString('koperasi', slKoperasi);
- prefs.setString('url', slUrl);
- prefs.setString('url_splash', slUrlSplash);
- prefs.setString('version', res['version']);
- prefs.setString('sl_username', usernameController.text);
- var body = {
- 'username': usernameController.text,
- 'password': passwordController.text,
- 'hp': slHp,
- 'fingerprint': slFingerprint,
- 'simid': slSimid,
- };
- var url = slUrl + "apiklien/loginClient";
- http
- .post(
- url,
- body: body,
- )
- .then((response) {
- var res = json.decode(response.body);
- if (res['st'] == 1) {
- setState(() {
- slSimid = "";
- noAnggota = res['no_anggota'];
- slToken = res['token_id'];
- slTokenKey = res['token_key'];
- generateQR = res['qr_code'];
- prefs.setString('sl_simid', slSimid);
- prefs.setString('sl_hpLogin', slHp);
- prefs.setString('sl_tokenid', slToken);
- prefs.setString('sl_tokenkey', slTokenKey);
- prefs.setString('nama', res['nama']);
- prefs.setString('no_anggota', noAnggota);
- prefs.setString(
- 'img', slUrl + "public/images/anggota/" + res['img']);
- prefs.setString('qr_code', generateQR);
- prefs.setBool('cek_login', true);
- Navigator.pushAndRemoveUntil(
- context,
- SlideRightRoute(page: MenuTab()),
- (Route<dynamic> route) => false);
- });
- } else if (res['st'] == 404) {
- showDialog(
- context: context,
- builder: (context) {
- return AlertDialog(
- title: Text("Galat!"),
- content: Text(
- "Akun SAKTI.Link Anda masih aktif di perangkat lain. Silahkan reset akun untuk dapat masuk kembali di perangkat ."),
- actions: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- FlatButton(
- child: Text("LAIN KALI"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- ),
- FlatButton(
- child: Text("RESET AKUN"),
- onPressed: () {
- Navigator.of(context).pop();
- showDialog(
- context: context,
- builder: (context) => AlertDialog(
- title: Text("Pilih Metode Reset"),
- content: Text(
- "Anda dapat mereset akun via nomor HP atau pun Email. Pastikan Nomor HP/Email yang akan digunakan dalam keadaan aktif. "),
- actions: <Widget>[
- Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: <Widget>[
- FlatButton(
- child: Text("VIA SMS"),
- onPressed: () {
- tipeReset = 'sms';
- Navigator.push(
- context,
- SlideRightRoute(
- page: ResetAkunPage(
- tipeReset)));
- },
- ),
- FlatButton(
- child: Text("VIA EMAIL"),
- onPressed: () {
- tipeReset = 'email';
- Navigator.push(
- context,
- SlideRightRoute(
- page: ResetAkunPage(
- tipeReset)));
- },
- ),
- ],
- )
- ],
- ));
- },
- ),
- ],
- )
- ],
- );
- },
- );
- } else if (res['st'] == 0) {
- showDialog(
- context: context,
- builder: (context) {
- return AlertDialog(
- title: Text("Perhatian"),
- content: Text("Nomer Ponsel atau sandi anda salah"),
- actions: <Widget>[
- FlatButton(
- child: Text("Ok"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- )
- ],
- );
- },
- );
- } else if (res['st'] == 2) {
- showDialog(
- context: context,
- builder: (context) {
- return AlertDialog(
- title: Text("Perhatian"),
- content: Text(
- "Silahkan masuk kembali menggunakan kata sandi anda"),
- actions: <Widget>[
- FlatButton(
- child: Text("Ok"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- )
- ],
- );
- },
- );
- } else {
- showDialog(
- context: context,
- builder: (context) {
- return AlertDialog(
- title: Text("Perhatian"),
- content: Text(
- "Jaringan anda sedang bermasalah, mohon coba lagi"),
- actions: <Widget>[
- FlatButton(
- child: Text("Ok"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- )
- ],
- );
- },
- );
- }
- });
- });
- } else {
- showDialog(
- context: context,
- builder: (context) {
- return AlertDialog(
- content: Text(res['status']['message']),
- actions: <Widget>[
- FlatButton(
- child: Text("Ok"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- )
- ],
- );
- },
- );
- }
- });
- }
- @override
- Widget build(BuildContext context) {
- final formnohp = Padding(
- padding: EdgeInsets.only(top: 25, left: 40, right: 40, bottom: 18),
- child: TextFormField(
- keyboardType: TextInputType.number,
- cursorColor: Colors.black,
- controller: usernameController,
- decoration: InputDecoration(
- fillColor: Colors.transparent,
- prefixIcon: Icon(
- Icons.smartphone,
- color: Color(0xFFFFF03A51),
- ),
- filled: true,
- hintText: 'Nomor ponsel',
- enabledBorder: UnderlineInputBorder(
- borderSide: BorderSide(
- color: Color(0xFFFFF03A51),
- ),
- ),
- focusedBorder: UnderlineInputBorder(
- borderSide: BorderSide(
- color: Color(0xFFFFF03A51),
- )),
- contentPadding: EdgeInsets.fromLTRB(20.0, 17.0, 20.0, 10.0)),
- ),
- );
- final formsandi = Padding(
- padding: EdgeInsets.only(top: 1, left: 40, right: 40),
- child: TextFormField(
- keyboardType: TextInputType.text,
- cursorColor: Colors.black,
- controller: passwordController,
- obscureText: !_obscureText,
- decoration: InputDecoration(
- fillColor: Colors.transparent,
- prefixIcon: Icon(
- Icons.lock,
- color: Color(0xFFFFF03A51),
- ),
- filled: true,
- hintText: 'Sandi',
- enabledBorder: UnderlineInputBorder(
- borderSide: BorderSide(
- color: Color(0xFFFFF03A51),
- ),
- ),
- focusedBorder: UnderlineInputBorder(
- borderSide: BorderSide(
- color: Color(0xFFFFF03A51),
- )),
- suffixIcon: GestureDetector(
- onTap: () {
- setState(() {
- _obscureText = !_obscureText;
- });
- },
- child: Icon(
- _obscureText ? Icons.visibility : Icons.visibility_off,
- color: Color(0xFFFFF03A51),
- semanticLabel: _obscureText ? 'show password' : 'hide password',
- ),
- ),
- contentPadding: EdgeInsets.fromLTRB(20.0, 17.0, 20.0, 10.0)),
- ),
- );
- final image = Padding(
- padding: EdgeInsets.only(top: 20, bottom: 25),
- child: Image(
- image: AssetImage("lib/assets/main-logo.png"),
- width: 150,
- height: 150,
- ));
- // final simpan = Container(
- // margin: EdgeInsets.all(10),
- // child: Material(
- // child: MaterialButton(
- // shape: RoundedRectangleBorder(
- // borderRadius: BorderRadius.all(Radius.circular(5.0)),
- // ),
- // minWidth: 344.0,
- // height: 47.0,
- // materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
- // color: Color(0xFFFFF03A51),
- // child: Text('Simpan',
- // style: TextStyle(color: Colors.white, fontSize: 18.0)),
- // onPressed: () {
- // login();
- // },
- // ),
- // ),
- // );
- return Scaffold(
- backgroundColor: Colors.white,
- resizeToAvoidBottomPadding: false,
- body: Stack(
- children: <Widget>[
- ListView(
- children: <Widget>[
- image,
- Center(
- child: Text(
- koperasi,
- style: TextStyle(
- color: Color(0xFFFFF03A51),
- ),
- ),
- ),
- formnohp,
- formsandi,
- Align(
- alignment: Alignment.bottomCenter,
- child: Image.asset("lib/assets/login-background.png"))
- ],
- ),
- ],
- ),
- floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
- floatingActionButton: Padding(
- padding: EdgeInsets.all(20),
- child: Container(
- width: double.infinity,
- child: OutlineButton(
- borderSide: BorderSide(color: Colors.white),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.all(Radius.circular(5.0)),
- ),
- child: Text(
- "Login",
- style: TextStyle(fontSize: 12, color: Colors.white),
- ),
- onPressed: () {
- login();
- },
- ),
- )
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement