Skip to content

Commit

Permalink
[#3] Add Splash screen
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangnguyen92dn committed Mar 9, 2023
1 parent 742594a commit 7b113ac
Show file tree
Hide file tree
Showing 6 changed files with 411 additions and 216 deletions.
Binary file added assets/images/bg_splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions assets/images/ic_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 9 additions & 29 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:survey_flutter_ic/gen/assets.gen.dart';
import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:survey_flutter_ic/ui/splash_screen.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -12,7 +13,7 @@ void main() async {
}

const routePathRootScreen = '/';
const routePathSecondScreen = 'second';
const routePathHomeScreen = '/home';

class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
Expand All @@ -22,14 +23,12 @@ class MyApp extends StatelessWidget {
GoRoute(
path: routePathRootScreen,
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen(),
routes: [
GoRoute(
path: routePathSecondScreen,
builder: (BuildContext context, GoRouterState state) =>
const SecondScreen(),
),
],
const SplashScreen(),
),
GoRoute(
path: routePathHomeScreen,
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen(),
),
],
);
Expand All @@ -51,6 +50,7 @@ class MyApp extends StatelessWidget {
}
}

// TODO: Extract to new class
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);

Expand Down Expand Up @@ -83,29 +83,9 @@ class HomeScreen extends StatelessWidget {
FlutterConfig.get('SECRET'),
style: const TextStyle(color: Colors.black, fontSize: 24),
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () => context.go('/$routePathSecondScreen'),
child: const Text("Navigate to Second Screen"),
),
],
),
),
);
}
}

class SecondScreen extends StatelessWidget {
const SecondScreen({
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Second Screen"),
),
);
}
}
41 changes: 41 additions & 0 deletions lib/ui/splash_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:survey_flutter_ic/gen/assets.gen.dart';
import 'package:survey_flutter_ic/main.dart';

const delayInMilliseconds = 2000;

class SplashScreen extends StatefulWidget {
const SplashScreen({Key? key}) : super(key: key);

@override
State<SplashScreen> createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(statusBarColor: Colors.transparent));
Future.delayed(const Duration(milliseconds: delayInMilliseconds), () {
context.go(routePathHomeScreen);
});
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: Assets.images.bgSplash.provider(), fit: BoxFit.fill),
),
child: Center(
child: Assets.images.icLogo.svg(),
),
),
);
}
}
Loading

0 comments on commit 7b113ac

Please sign in to comment.