Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#3] [UI] As a user, I can see the Splash screen #40

Merged
merged 7 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.3.10'
flutter-version: '3.7.7'

- name: Get flutter dependencies.
run: flutter pub get
Expand Down
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.
36 changes: 8 additions & 28 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 @@ -21,15 +22,13 @@ class MyApp extends StatelessWidget {
routes: <GoRoute>[
GoRoute(
path: routePathRootScreen,
builder: (BuildContext context, GoRouterState state) =>
hoangnguyen92dn marked this conversation as resolved.
Show resolved Hide resolved
const SplashScreen(),
),
GoRoute(
path: routePathHomeScreen,
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen(),
routes: [
GoRoute(
path: routePathSecondScreen,
builder: (BuildContext context, GoRouterState state) =>
const SecondScreen(),
),
],
),
],
);
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"),
),
);
}
}
60 changes: 60 additions & 0 deletions lib/ui/splash_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 _splashTransitionDelayInMilliseconds = 2000;
const _logoVisibilityDelayInMilliseconds = 500;
const _logoVisibilityAnimationInMilliseconds = 1000;

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

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

class _SplashScreenState extends State<SplashScreen> {
bool _logoVisible = false;

@override
void initState() {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(statusBarColor: Colors.transparent));

Future.delayed(
const Duration(milliseconds: _splashTransitionDelayInMilliseconds), () {
context.go(routePathHomeScreen);
});

Future.delayed(
const Duration(milliseconds: _logoVisibilityDelayInMilliseconds), () {
setState(() {
_logoVisible = true;
});
});

super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(Assets.images.bgSplash.path), fit: BoxFit.fill),
),
child: Center(
child: AnimatedOpacity(
duration: const Duration(
milliseconds: _logoVisibilityAnimationInMilliseconds),
opacity: _logoVisible ? 1.0 : 0.0,
child: Assets.images.icLogo.svg(),
),
),
),
);
}
}
Loading