step 3 : login proses
This commit is contained in:
113
lib/screen/splash/splash_screen.dart
Normal file
113
lib/screen/splash/splash_screen.dart
Normal file
@@ -0,0 +1,113 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../app/constant.dart';
|
||||
import '../../app/route.dart';
|
||||
import '../../model/auth_model.dart';
|
||||
import '../../provider/current_user_provider.dart';
|
||||
|
||||
class SplashScreen extends HookConsumerWidget {
|
||||
const SplashScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [
|
||||
SystemUiOverlay.bottom,
|
||||
]);
|
||||
|
||||
useEffect(() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
final shared = await SharedPreferences.getInstance();
|
||||
final bearerString = shared.getString(Constant.bearerName);
|
||||
|
||||
if (bearerString == null || bearerString == "null") {
|
||||
Timer(const Duration(seconds: 3), () {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
loginRoute,
|
||||
(route) => false,
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
final xmodel = jsonDecode(bearerString);
|
||||
if (xmodel == null) return;
|
||||
|
||||
final authModel = AuthModel(
|
||||
host: xmodel["host"],
|
||||
token: xmodel["token"],
|
||||
model: UserModel(
|
||||
userId: xmodel["model"]['M_UserID'],
|
||||
username: xmodel["model"]['M_UserUsername'],
|
||||
groupDashboard: xmodel["model"]['M_UserGroupDashboard'],
|
||||
defaultSampleStationId: xmodel["model"]
|
||||
['M_UserDefaultT_SampleStationID'],
|
||||
staffName: xmodel["model"]['M_StaffName'],
|
||||
isCourier: xmodel["model"]['is_courier'],
|
||||
timeAutoLogout: xmodel["model"]['time_autologout'],
|
||||
ip: xmodel["model"]['ip'],
|
||||
agent: xmodel["model"]['agent'],
|
||||
version: xmodel["model"]['version'],
|
||||
lastLogin: xmodel["model"]['last-login'],
|
||||
satelliteId: xmodel["model"]['M_SatelliteID'],
|
||||
),
|
||||
);
|
||||
|
||||
ref.read(currentUserProvider.notifier).state = authModel;
|
||||
|
||||
Timer(const Duration(seconds: 3), () {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
homeRoute,
|
||||
(route) => false,
|
||||
);
|
||||
});
|
||||
});
|
||||
return () {};
|
||||
}, []);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Constant.textWhite,
|
||||
body: Column(
|
||||
children: [
|
||||
// Bagian atas
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: SizedBox(
|
||||
width: Constant.getActualXPhone(context: context, x: 246),
|
||||
child: Image.asset(
|
||||
'images/splashatas.png',
|
||||
fit: BoxFit.fitWidth,
|
||||
),
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
// Logo di tengah
|
||||
Center(
|
||||
child: Image.asset(
|
||||
'images/logo.png',
|
||||
width: Constant.getActualXPhone(context: context, x: 164),
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
// Bagian bawah
|
||||
Align(
|
||||
alignment: Alignment.bottomLeft,
|
||||
child: SizedBox(
|
||||
width: Constant.getActualXPhone(context: context, x: 246),
|
||||
child: Image.asset(
|
||||
'images/splashbawah.png',
|
||||
fit: BoxFit.fitWidth,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user