102 lines
2.9 KiB
Dart
102 lines
2.9 KiB
Dart
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 '../../model/no-login/no_login_auth_model.dart';
|
|
import '../../provider/no-login/no_login_current_user_provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../app/constant.dart';
|
|
import '../../app/route.dart';
|
|
|
|
class NoLoginSplashScreen extends HookConsumerWidget {
|
|
const NoLoginSplashScreen({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(
|
|
noLoginRoute,
|
|
(route) => false,
|
|
);
|
|
});
|
|
return;
|
|
}
|
|
|
|
final xmodel = jsonDecode(bearerString);
|
|
if (xmodel == null) return;
|
|
|
|
final authModel = NoLoginAuthModel(
|
|
host: xmodel["host"],
|
|
token: xmodel["token"],
|
|
client_id: xmodel['client_id'],
|
|
expire_date: xmodel['expire_date'],
|
|
isLogin: xmodel['isLogin'],
|
|
);
|
|
|
|
ref.read(noLoginCurrentUserProvider.notifier).state = authModel;
|
|
|
|
Timer(const Duration(seconds: 2), () {
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
noLoginHomeRoute,
|
|
(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,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|