From 222a16e620e3f22a1274cb19200727fefeb30329 Mon Sep 17 00:00:00 2001 From: Markin Igor <markin.io210@gmail.com> Date: Fri, 26 Jul 2019 15:33:50 +0500 Subject: [PATCH] Use custom splash screen. --- lib/src/app.dart | 42 ++++++++-------- lib/src/screens/splashscreen.dart | 80 +++++++++++++++++++++++++++++++ pubspec.lock | 7 --- pubspec.yaml | 1 - 4 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 lib/src/screens/splashscreen.dart diff --git a/lib/src/app.dart b/lib/src/app.dart index 6d72a7d..c33e29e 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -1,4 +1,5 @@ // app.dart +import 'screens/splashscreen.dart'; import 'package:flutter/material.dart'; import 'screens/home.dart'; import 'package:flutter/services.dart'; @@ -6,9 +7,22 @@ import 'dart:async'; import 'dart:developer'; import 'package:uni_links/uni_links.dart'; -import 'package:splashscreen/splashscreen.dart'; class App extends StatelessWidget { + Future<Widget> initApplication() async { + Uri initialUri; + + try { + initialUri = await getInitialUri(); + } on PlatformException { + initialUri = null; + } on FormatException { + initialUri = null; + } + + return new MainApp(initialUri: initialUri); + } + @override Widget build(BuildContext context) { return MaterialApp( @@ -20,16 +34,7 @@ class App extends StatelessWidget { button: TextStyle(color: Colors.white, fontSize: 18.0), title: TextStyle(color: Colors.red))), home: new SplashScreen( - seconds: 3, - title: new Text(''), - navigateAfterSeconds: new MainApp(), - image: new Image.asset('assets/images/vereign_logo_text.png'), - backgroundColor: Color(0xFFd51d32), - photoSize: 100.0, - loaderColor: Colors.white, - loadingText: new Text('Loading', style: new TextStyle( - color: Colors.white - )), + navigateAfterFuture: initApplication, ) ); @@ -38,6 +43,9 @@ class App extends StatelessWidget { } class MainApp extends StatefulWidget { + MainApp({ @required this.initialUri }); + final Uri initialUri; + @override _MainAppState createState() => _MainAppState(); } @@ -55,7 +63,6 @@ class _MainAppState extends State<MainApp> { initState() { super.initState(); initUniLinks(); -// FlutterWebBrowser.openWebPage(url: 'https://demo1.vereign.com', androidToolbarColor: Color(0xFFd51d32)); } @override @@ -65,16 +72,7 @@ class _MainAppState extends State<MainApp> { } Future<Null> initUniLinks() async { - Uri initialUri; - - try { - initialUri = await getInitialUri(); - } on PlatformException { - initialUri = null; - } on FormatException { - initialUri = null; - } - updateAppMode(initialUri); + updateAppMode(widget.initialUri); _sub = getUriLinksStream().listen((Uri uri) { updateAppMode(uri); diff --git a/lib/src/screens/splashscreen.dart b/lib/src/screens/splashscreen.dart new file mode 100644 index 0000000..44bd75c --- /dev/null +++ b/lib/src/screens/splashscreen.dart @@ -0,0 +1,80 @@ +import 'dart:core'; +import 'dart:async'; +import 'package:flutter/material.dart'; + +class SplashScreen extends StatefulWidget { + final dynamic navigateAfterFuture; + SplashScreen({this.navigateAfterFuture}); + + @override + _SplashScreenState createState() => _SplashScreenState(); +} + +class _SplashScreenState extends State<SplashScreen> { + @override + void initState() { + super.initState(); + + load(); + } + + load() async { + var newWidget = await widget.navigateAfterFuture(); + + // Show loader additional 2 seconds + Timer( + Duration(seconds: 2), + () { + Navigator.of(context).pushReplacement(new MaterialPageRoute(builder: (BuildContext context) => newWidget)); + } + ); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: new InkWell( + child:new Stack( + fit: StackFit.expand, + children: <Widget>[ + new Container( + decoration: new BoxDecoration( + color: Color(0xFFd51d32), + ), + ), + new Column( + mainAxisAlignment: MainAxisAlignment.start, + children: <Widget>[ + new Expanded( + flex: 2, + child: new Container( + child: new Image.asset('assets/images/vereign_logo_text.png'), + padding: EdgeInsets.all(40) + ), + ), + Expanded( + flex: 1, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + + CircularProgressIndicator( + valueColor: new AlwaysStoppedAnimation<Color>(Colors.white), + ), + Padding( + padding: const EdgeInsets.only(top: 20.0), + ), + new Text('Loading', style: new TextStyle( + color: Colors.white + )) + ], + ), + ), + ], + ), + ], + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 5450bc0..53b08bf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -172,13 +172,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.5.5" - splashscreen: - dependency: "direct main" - description: - name: splashscreen - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" stack_trace: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b61d589..fded95b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,7 +29,6 @@ dependencies: http: ^0.12.0 flutter_app_auth_wrapper: ^0.1.1+3 url_launcher: 5.1.0 - splashscreen: 1.2.0 dev_dependencies: flutter_test: -- GitLab