Files
fcs/lib/pages/splash.dart
Sai Naw Wun 3f6a66b887 add pickups
2020-05-31 15:00:11 +06:30

146 lines
4.1 KiB
Dart

import 'dart:async';
import 'package:fcs/model/main_model.dart';
import 'package:fcs/theme/theme.dart';
import 'package:fcs/widget/local_text.dart';
import 'package:fcs/widget/localization/app_translations.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:provider/provider.dart';
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => new _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
final log = Logger('_SplashScreenState');
bool _loaded = false;
bool _isSupport = false;
bool _isGoogleService = true;
bool _isLogin = false;
bool _isAgree = false;
bool _hasEmail = false;
bool _isOnline = true;
Timer timer;
startTime() async {
var _duration = new Duration(milliseconds: 1000);
this.timer = new Timer.periodic(_duration, navigationPage);
}
void navigationPage(Timer timer) async {
if (!_isOnline) {
return;
}
// GooglePlayServicesAvailability availability = await GoogleApiAvailability
// .instance
// .checkGooglePlayServicesAvailability(true);
// log.info("GooglePlaysServcie Result1:$availability");
// if (availability != GooglePlayServicesAvailability.success &&
// Platform.isAndroid) {
// timer.cancel();
// setState(() {
// _isGoogleService = false;
// });
// return;
// }
if (_loaded) {
timer.cancel();
Navigator.of(context).pushReplacementNamed('/home');
// if (_isSupport) {
// if (_isLogin) {
// if (!_isAgree) {
// await Navigator.of(context).pushNamed('/term');
// startTime();
// } else {
// bool skipped = await SharedPref.getSkippedRecoverEmail();
// skipped = skipped ?? false;
// if (!this._hasEmail && !skipped) {
// Navigator.of(context).pushReplacementNamed('/email');
// } else {
// }
// }
// } else {
// Navigator.of(context).pushReplacementNamed('/welcome');
// }
// }
}
}
@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);
this._loaded = mainModel.isLoaded;
this._isSupport = true;
this._isLogin = mainModel.isLogin();
this._isAgree = mainModel.agreedTerm();
this._hasEmail = mainModel.hasEmail();
this._isOnline = mainModel.isOnline;
return new Scaffold(
backgroundColor: Colors.white,
body: new Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image.asset(
"assets/logo.jpg",
width: 180,
),
SizedBox(height: 50),
Column(
children: <Widget>[
Text(
"Cargo Services",
style: welcomeLabelStyle,
),
Text(
"by FCS Trading",
style: welcomeSubLabelStyle,
),
],
),
// CircularProgressIndicator(
// valueColor: new AlwaysStoppedAnimation<Color>(primaryColor),
// ),
SizedBox(height: 30),
_isOnline
? Container()
: Column(
children: <Widget>[
LocalText(context, "offline.status"),
],
),
Text(_isGoogleService ? "" : "Google Play service not found."),
Text(
_loaded
? (!_isSupport
? "Version outdated, please update your app!"
: "")
: AppTranslations.of(context).text("load"),
style: TextStyle(
color: primaryColor, fontWeight: FontWeight.bold)),
],
),
),
);
}
}