Skip to content

Commit

Permalink
fix: resolve native splash screen android ios (#24)
Browse files Browse the repository at this point in the history
* chore: change launcher icon

* chore: update library version

* docs: update syntax to generate launcher icon

* fix: resolve splashscreen issue on iOS

* fix: resolve splashscreen issue on android <12 and >=12

* fix(test): resolve the test issue regarding new flutter version
  • Loading branch information
Lzyct authored Nov 2, 2023
1 parent 13c1f46 commit ac7b038
Show file tree
Hide file tree
Showing 95 changed files with 121 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ https://github.com/lazycatlabs/flutter_auth_app/assets/1531684/53f880ed-d51e-4bc
- Run `flutter run --flavor stg -t lib/main.dart --dart-define-from-file .env.stg.json` for **staging** or
- Run `flutter run --flavor prd -t lib/main.dart --dart-define-from-file .env.prd.json` for **production**
- Run Test `flutter test`
- To generate launcher icon based on Flavor `dart pub run flutter_launcher_icons:main -f flutter_launcher_icons*`
- To generate launcher icon based on Flavor `dart run flutter_launcher_icons`
- To generate mock class `dart pub run build_runner build`


Expand Down
15 changes: 15 additions & 0 deletions android/app/src/main/kotlin/com/lazycatlabs/base/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
package com.lazycatlabs.auth

import android.os.Build
import android.os.Bundle
import androidx.core.view.WindowCompat
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Aligns the Flutter view vertically with the window.
WindowCompat.setDecorFitsSystemWindows(getWindow(), false)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Disable the Android splash screen fade out animation to avoid
// a flicker before the similar frame is drawn in Flutter.
splashScreen.setOnExitAnimationListener { splashScreenView -> splashScreenView.remove() }
}

super.onCreate(savedInstanceState)
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 8 additions & 6 deletions android/app/src/main/res/drawable/launch_background.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/ic_launcher_background" />

<!-- You can insert your own image assets here -->
<!-- <item>
<item android:drawable="@color/ic_launcher_background"/>
<item
android:height="350dp"
android:width="350dp"
android:gravity="center">
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
android:gravity="fill_horizontal|fill_vertical"
android:src="@drawable/ic_splash"/>
</item>
</layer-list>
14 changes: 14 additions & 0 deletions android/app/src/main/res/drawable/launch_background_12.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- You can insert your own image assets here -->
<item android:drawable="@color/ic_launcher_background"/>
<item
android:height="350dp"
android:width="350dp"
android:gravity="fill_horizontal|fill_vertical">
<bitmap
android:gravity="fill_horizontal|fill_vertical"
android:src="@drawable/ic_splash"/>
</item>
</layer-list>
2 changes: 1 addition & 1 deletion android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#ffffff</color>
<color name="ic_launcher_background">#1E1E2E</color>
</resources>
11 changes: 11 additions & 0 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<item name="android:forceDarkAllowed">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowLightStatusBar">true</item>


<item name="android:windowSplashScreenBackground">@color/ic_launcher_background</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/launch_background_12</item>

</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/prd/res/drawable/ic_splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/prd/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/prd/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/prd/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/prd/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/prd/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added android/app/src/stg/res/drawable/ic_splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/stg/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/stg/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/stg/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/stg/res/mipmap-xxhdpi/ic_launcher.png
Binary file modified android/app/src/stg/res/mipmap-xxxhdpi/ic_launcher.png
Binary file modified assets/images/ic_launcher.png
Binary file modified assets/images/ic_launcher_foreground.png
Binary file modified assets/images/ic_launcher_foreground_stg.png
Binary file modified assets/images/ic_launcher_stg.png
Binary file modified assets/images/ic_logo.png
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3

COCOAPODS: 1.13.0
COCOAPODS: 1.14.2
10 changes: 5 additions & 5 deletions ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"images" : [
{
"filename" : "ic_launcher_foreground 2.png",
"idiom" : "universal",
"filename" : "LaunchImage.png",
"scale" : "1x"
},
{
"filename" : "ic_launcher_foreground 1.png",
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"filename" : "ic_launcher_foreground.png",
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
Diff not rendered.
Diff not rendered.
Diff not rendered.
20 changes: 12 additions & 8 deletions ios/Runner/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -13,13 +15,15 @@
<viewControllerLayoutGuide type="top" id="Ydg-fD-yQy"/>
<viewControllerLayoutGuide type="bottom" id="xbc-2k-c8Z"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<view key="view" contentMode="scaleAspectFit" semanticContentAttribute="spatial" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4">
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleAspectFit" semanticContentAttribute="spatial" misplaced="YES" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4">
<rect key="frame" x="0.0" y="336" width="393" height="181"/>
</imageView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.11764705882352941" green="0.11764705882352941" blue="0.1803921568627451" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="1a2-6s-vTC"/>
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="4X2-HB-R7a"/>
Expand All @@ -28,10 +32,10 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
<point key="canvasLocation" x="80.152671755725194" y="264.08450704225356"/>
</scene>
</scenes>
<resources>
<image name="LaunchImage" width="168" height="185"/>
<image name="LaunchImage" width="1480" height="1480"/>
</resources>
</document>
45 changes: 24 additions & 21 deletions lib/features/users/pages/dashboard/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,30 @@ class _DashboardPageState extends State<DashboardPage> {
),
),
SpacerH(value: Dimens.space16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_users[index].name ?? "",
style: Theme.of(context)
.textTheme
.titleLargeBold,
),
Text(
_users[index].email ?? "",
style: Theme.of(context)
.textTheme
.bodySmall
?.copyWith(
color: Theme.of(context)
.extension<LzyctColors>()!
.subtitle,
),
),
],
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
_users[index].name ?? "",
style: Theme.of(context)
.textTheme
.titleLargeBold,
),
Text(
_users[index].email ?? "",
style: Theme.of(context)
.textTheme
.bodySmall
?.copyWith(
color: Theme.of(context)
.extension<LzyctColors>()!
.subtitle,
),
),
],
),
),
],
),
Expand Down
4 changes: 0 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ version: 1.0.0+1
environment:
sdk: ^3.0.0

dependency_overrides:
intl: ^0.18.1
analyzer: ^6.0.0

dependencies:
flutter:
sdk: flutter
Expand Down
6 changes: 6 additions & 0 deletions test/features/auth/pages/login/login_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void main() {
(tester) async {
when(() => authCubit.state).thenReturn(const AuthState.success(null));
await tester.pumpWidget(rootWidget(const LoginPage()));
await tester.pumpAndSettle();
await tester.dragUntilVisible(
find.byType(Button), // what you want to find
find.byType(SingleChildScrollView), // widget you want to scroll
Expand All @@ -88,7 +89,9 @@ void main() {
when(() => authCubit.state).thenReturn(const AuthState.success(null));

await tester.pumpWidget(rootWidget(const LoginPage()));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('email')), email);
await tester.pumpAndSettle();
await tester.dragUntilVisible(
find.byType(Button), // what you want to find
find.byType(SingleChildScrollView), // widget you want to scroll
Expand Down Expand Up @@ -116,9 +119,12 @@ void main() {
when(() => authCubit.login(any())).thenAnswer((_) async {});

await tester.pumpWidget(rootWidget(const LoginPage()));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('email')), email);
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('password')), password);

await tester.pumpAndSettle();
await tester.dragUntilVisible(
find.byType(Button), // what you want to find
find.byType(SingleChildScrollView), // widget you want to scroll
Expand Down
19 changes: 16 additions & 3 deletions test/features/auth/pages/register/register_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void main() {
when(() => registerCubit.state)
.thenReturn(const RegisterState.success(null));
await tester.pumpWidget(rootWidget(const RegisterPage()));
await tester.pumpAndSettle();
await tester.dragUntilVisible(
find.byKey(const Key('btn_register')), // what you want to find
find.byType(SingleChildScrollView), // widget you want to scroll
Expand All @@ -76,7 +77,9 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
expect(find.text("Email is not valid"), findsOneWidget);
expect(
find.text("Password must be at least 6 characters"), findsOneWidget,);
find.text("Password must be at least 6 characters"),
findsOneWidget,
);
},
);

Expand All @@ -89,7 +92,9 @@ void main() {
.thenReturn(const RegisterState.success(null));

await tester.pumpWidget(rootWidget(const RegisterPage()));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('email')), email);
await tester.pumpAndSettle();
await tester.dragUntilVisible(
find.byKey(const Key('btn_register')), // what you want to find
find.byType(SingleChildScrollView), // widget you want to scroll
Expand All @@ -101,7 +106,9 @@ void main() {
await tester.pump(const Duration(milliseconds: 100));
expect(find.text("Email is not valid"), findsNothing);
expect(
find.text("Password must be at least 6 characters"), findsOneWidget,);
find.text("Password must be at least 6 characters"),
findsOneWidget,
);
},
);

Expand All @@ -114,6 +121,7 @@ void main() {
when(() => registerCubit.state)
.thenReturn(const RegisterState.success(null));
await tester.pumpWidget(rootWidget(const RegisterPage()));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('email')), email);
await tester.enterText(find.byKey(const Key('password')), password);

Expand Down Expand Up @@ -142,10 +150,12 @@ void main() {
when(() => registerCubit.state)
.thenReturn(const RegisterState.success(null));
await tester.pumpWidget(rootWidget(const RegisterPage()));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('email')), email);
await tester.enterText(find.byKey(const Key('password')), password);
await tester.enterText(find.byKey(const Key('repeat_password')), '');

await tester.pumpAndSettle();
await tester.dragUntilVisible(
find.byKey(const Key('btn_register')), // what you want to find
find.byType(SingleChildScrollView), // widget you want to scroll
Expand All @@ -172,13 +182,16 @@ void main() {
when(() => registerCubit.register(any())).thenAnswer((_) async {});

await tester.pumpWidget(rootWidget(const RegisterPage()));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('email')), email);
await tester.pumpAndSettle();
await tester.enterText(find.byKey(const Key('password')), password);
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('repeat_password')),
password,
);

await tester.pumpAndSettle();
await tester.dragUntilVisible(
find.byKey(const Key('btn_register')), // what you want to find
find.byType(SingleChildScrollView), // widget you want to scroll
Expand Down
2 changes: 2 additions & 0 deletions test/features/general/pages/settings/settings_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void main() {
when(() => settingsCubit.state).thenReturn(DataHelper());

await tester.pumpWidget(rootWidget(const SettingsPage()));
await tester.pumpAndSettle();
final dropdown = find.byKey(const Key("dropdown_theme")).last;

await tester.tap(dropdown);
Expand All @@ -83,6 +84,7 @@ void main() {
when(() => settingsCubit.state).thenReturn(DataHelper());

await tester.pumpWidget(rootWidget(const SettingsPage()));
await tester.pumpAndSettle();
final dropdown = find.byKey(const Key("dropdown_language")).last;

await tester.tap(dropdown);
Expand Down
Loading

0 comments on commit ac7b038

Please sign in to comment.