2020-05-29 07:45:27 +06:30
|
|
|
import 'dart:async';
|
|
|
|
|
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/main/model/main_model.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
2020-05-31 15:00:11 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
2020-05-29 07:45:27 +06:30
|
|
|
|
|
|
|
|
class SplashScreen extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
_SplashScreenState createState() => new _SplashScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SplashScreenState extends State<SplashScreen> {
|
|
|
|
|
final log = Logger('_SplashScreenState');
|
2020-09-12 03:34:52 +06:30
|
|
|
String page = "/language_selection";
|
2020-05-29 07:45:27 +06:30
|
|
|
bool _loaded = false;
|
|
|
|
|
bool _isSupport = false;
|
|
|
|
|
bool _isOnline = true;
|
2021-09-10 12:00:08 +06:30
|
|
|
late Timer timer;
|
2020-05-29 07:45:27 +06:30
|
|
|
|
|
|
|
|
startTime() async {
|
2020-09-12 03:34:52 +06:30
|
|
|
var _duration = new Duration(milliseconds: 3000);
|
2020-05-29 07:45:27 +06:30
|
|
|
this.timer = new Timer.periodic(_duration, navigationPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void navigationPage(Timer timer) async {
|
2020-09-12 03:34:52 +06:30
|
|
|
if (_loaded && _isOnline && _isSupport) {
|
2020-05-29 07:45:27 +06:30
|
|
|
timer.cancel();
|
2020-09-12 03:34:52 +06:30
|
|
|
Navigator.of(context).pushReplacementNamed(page);
|
2020-05-29 07:45:27 +06:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
startTime();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
if (timer.isActive) timer.cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context);
|
|
|
|
|
|
2020-09-04 01:42:58 +06:30
|
|
|
this._isSupport = mainModel.isSupport();
|
2020-05-29 07:45:27 +06:30
|
|
|
this._isOnline = mainModel.isOnline;
|
2020-09-12 03:34:52 +06:30
|
|
|
if (mainModel.isLoaded) {
|
|
|
|
|
if (mainModel.isFirstLaunch) {
|
|
|
|
|
page = "/language_selection";
|
2020-09-13 21:49:39 +06:30
|
|
|
} else if (mainModel.isLogin()) {
|
2020-09-12 03:34:52 +06:30
|
|
|
page = "/home";
|
|
|
|
|
} else {
|
|
|
|
|
page = "/welcome";
|
|
|
|
|
}
|
|
|
|
|
this._loaded = mainModel.isLoaded;
|
|
|
|
|
}
|
2020-05-29 07:45:27 +06:30
|
|
|
|
|
|
|
|
return new Scaffold(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
body: new Center(
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: <Widget>[
|
2020-11-09 05:53:25 +06:30
|
|
|
Container(
|
|
|
|
|
height: 180,
|
2020-05-29 07:45:27 +06:30
|
|
|
width: 180,
|
2020-11-09 05:53:25 +06:30
|
|
|
child: new Image.asset(
|
|
|
|
|
"assets/logo.jpg",
|
|
|
|
|
),
|
2020-05-29 07:45:27 +06:30
|
|
|
),
|
|
|
|
|
SizedBox(height: 50),
|
2020-05-31 15:00:11 +06:30
|
|
|
Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Text(
|
2020-09-12 03:34:52 +06:30
|
|
|
"FCS Logistics",
|
2020-05-31 15:00:11 +06:30
|
|
|
style: welcomeSubLabelStyle,
|
|
|
|
|
),
|
|
|
|
|
],
|
2020-05-29 07:45:27 +06:30
|
|
|
),
|
|
|
|
|
SizedBox(height: 30),
|
2020-09-04 01:42:58 +06:30
|
|
|
_loaded && !_isOnline
|
|
|
|
|
? Column(
|
2020-05-29 07:45:27 +06:30
|
|
|
children: <Widget>[
|
|
|
|
|
LocalText(context, "offline.status"),
|
|
|
|
|
],
|
2020-09-04 01:42:58 +06:30
|
|
|
)
|
|
|
|
|
: Container(),
|
2020-05-29 07:45:27 +06:30
|
|
|
Text(
|
2020-09-04 01:42:58 +06:30
|
|
|
_loaded && !_isSupport
|
|
|
|
|
? "Version outdated, please update your app!"
|
|
|
|
|
: "",
|
2020-05-29 07:45:27 +06:30
|
|
|
style: TextStyle(
|
|
|
|
|
color: primaryColor, fontWeight: FontWeight.bold)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|