add structure
This commit is contained in:
137
lib/pages/splash.dart
Normal file
137
lib/pages/splash.dart
Normal file
@@ -0,0 +1,137 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io' show Platform;
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_api_availability/google_api_availability.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/main_model.dart';
|
||||
import 'package:fcs/model/shared_pref.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.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: 500);
|
||||
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 = mainModel.isSupport();
|
||||
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.png",
|
||||
width: 180,
|
||||
),
|
||||
SizedBox(height: 50),
|
||||
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)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user