Skip to content

Commit 125bd2c

Browse files
authored
Add splash screen (#56)
1 parent 7965966 commit 125bd2c

40 files changed

+213
-104
lines changed

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# flutter-template
22

3-
### Project Setup
3+
## Project Setup
44

55
The project setup is based on some of plugins which generates the required native code.
66

7+
You can use [project_setup.sh](scripts/project_setup.sh) to reload all project setups.
8+
79
### Flavor setup: Project name, properties BundleId & Application id
810
This information is set using [flavorizr], a flutter utility to easily create flavors in your flutter application.
911
To change it go to flavorizr section in the [pubspec](./pubspec.yaml) file.
@@ -34,9 +36,22 @@ To change it go to flutter_icons section in the [pubspec](./pubspec.yaml) file.
3436
After a change is made, you need to regenerate your native files.
3537
You can do that by executing `flutter pub run flutter_launcher_icons:main`.
3638

39+
40+
### Splash screen
41+
42+
Splash screen is generated using [flutter_native_splash].
43+
To change it go to flutter_native_splash section in the [pubspec](./pubspec.yaml) file.
44+
45+
After a change is made, you need to regenerate your native files.
46+
You can do that by executing `flutter pub run flutter_native_splash:create`.
47+
48+
Although you can setup a bunch of features in this library, it doesn't provide a way to display animations.
49+
If you need a more personalized splash screen, you can edit the native code or just remove this library.
50+
3751
### Pre Push config
3852

3953
In order to setup pre-push hook you need to go to the root of the project and run `git config core.hooksPath .github/hooks`
4054

4155
[flavorizr]: https://pub.dev/packages/flutter_flavorizr
4256
[flutter_launcher_icons]: https://pub.dev/packages/flutter_launcher_icons
57+
[flutter_native_splash]: https://pub.dev/packages/flutter_native_splash

android/app/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ android {
5151
}
5252

5353
// ----- END flavorDimensions (autogenerated by flutter_flavorizr) -----
54-
compileSdkVersion 33
54+
55+
compileSdkVersion 33
5556

5657
compileOptions {
5758
sourceCompatibility JavaVersion.VERSION_1_8

android/app/src/main/AndroidManifest.xml

+1-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,7 @@
1919
android:name="io.flutter.embedding.android.NormalTheme"
2020
android:resource="@style/NormalTheme"
2121
/>
22-
<!-- Displays an Android View that continues showing the launch screen
23-
Drawable until Flutter paints its first frame, then this splash
24-
screen fades out. A splash screen is useful to avoid any visual
25-
gap between the end of Android's launch screen and the painting of
26-
Flutter's first frame. -->
27-
<meta-data
28-
android:name="io.flutter.embedding.android.SplashScreenDrawable"
29-
android:resource="@drawable/launch_background"
30-
/>
22+
3123
<intent-filter>
3224
<action android:name="android.intent.action.MAIN"/>
3325
<category android:name="android.intent.category.LAUNCHER"/>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- Modify this file to customize your launch splash screen -->
32
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4-
<item android:drawable="?android:colorBackground" />
5-
6-
<!-- You can insert your own image assets here -->
7-
<!-- <item>
8-
<bitmap
9-
android:gravity="center"
10-
android:src="@mipmap/launch_image" />
11-
</item> -->
3+
<item>
4+
<bitmap android:gravity="fill" android:src="@drawable/background"/>
5+
</item>
6+
<item>
7+
<bitmap android:gravity="center" android:src="@drawable/splash"/>
8+
</item>
129
</layer-list>
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
68 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- Modify this file to customize your launch splash screen -->
32
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4-
<item android:drawable="@android:color/white" />
5-
6-
<!-- You can insert your own image assets here -->
7-
<!-- <item>
8-
<bitmap
9-
android:gravity="center"
10-
android:src="@mipmap/launch_image" />
11-
</item> -->
3+
<item>
4+
<bitmap android:gravity="fill" android:src="@drawable/background"/>
5+
</item>
6+
<item>
7+
<bitmap android:gravity="center" android:src="@drawable/splash"/>
8+
</item>
129
</layer-list>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
4+
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
5+
<item name="android:forceDarkAllowed">false</item>
6+
<item name="android:windowFullscreen">false</item>
7+
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
8+
<item name="android:windowSplashScreenBackground">#ffffff</item>
9+
<item name="android:windowSplashScreenBrandingImage">@drawable/android12branding</item>
10+
<item name="android:windowSplashScreenAnimatedIcon">@drawable/android12splash</item>
11+
</style>
12+
<!-- Theme applied to the Android Window as soon as the process has started.
13+
This theme determines the color of the Android Window while your
14+
Flutter UI initializes, as well as behind your Flutter UI while its
15+
running.
16+
17+
This Theme is only used starting with V2 of Flutter's Android embedding. -->
18+
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
19+
<item name="android:windowBackground">?android:colorBackground</item>
20+
</style>
21+
</resources>

android/app/src/main/res/values/styles.xml

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<!-- Show a splash screen on the activity. Automatically removed when
66
Flutter draws its first frame -->
77
<item name="android:windowBackground">@drawable/launch_background</item>
8+
<item name="android:forceDarkAllowed">false</item>
9+
<item name="android:windowFullscreen">false</item>
10+
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
811
</style>
912
<!-- Theme applied to the Android Window as soon as the process has started.
1013
This theme determines the color of the Android Window while your

icons/splash_branding.png

8.12 KB
Loading

icons/splash_logo.png

16.1 KB
Loading

icons/splash_logo_android_12.png

11 KB
Loading

ios/Podfile.lock

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
PODS:
22
- Flutter (1.0.0)
3+
- flutter_native_splash (0.0.1):
4+
- Flutter
35
- flutter_secure_storage (3.3.1):
46
- Flutter
57
- flutter_web_browser (0.17.1):
@@ -15,6 +17,7 @@ PODS:
1517

1618
DEPENDENCIES:
1719
- Flutter (from `Flutter`)
20+
- flutter_native_splash (from `.symlinks/plugins/flutter_native_splash/ios`)
1821
- flutter_secure_storage (from `.symlinks/plugins/flutter_secure_storage/ios`)
1922
- flutter_web_browser (from `.symlinks/plugins/flutter_web_browser/ios`)
2023
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
@@ -27,6 +30,8 @@ SPEC REPOS:
2730
EXTERNAL SOURCES:
2831
Flutter:
2932
:path: Flutter
33+
flutter_native_splash:
34+
:path: ".symlinks/plugins/flutter_native_splash/ios"
3035
flutter_secure_storage:
3136
:path: ".symlinks/plugins/flutter_secure_storage/ios"
3237
flutter_web_browser:
@@ -38,6 +43,7 @@ EXTERNAL SOURCES:
3843

3944
SPEC CHECKSUMS:
4045
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
46+
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
4147
flutter_secure_storage: 7953c38a04c3fdbb00571bcd87d8e3b5ceb9daec
4248
flutter_web_browser: 7bccaafbb0c5b8862afe7bcd158f15557109f61f
4349
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "background.png",
5+
"idiom" : "universal",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"author" : "xcode",
19+
"version" : 1
20+
}
21+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"images" : [
33
{
4-
"idiom" : "universal",
54
"filename" : "LaunchImage.png",
5+
"idiom" : "universal",
66
"scale" : "1x"
77
},
88
{
9-
"idiom" : "universal",
109
"filename" : "[email protected]",
10+
"idiom" : "universal",
1111
"scale" : "2x"
1212
},
1313
{
14-
"idiom" : "universal",
1514
"filename" : "[email protected]",
15+
"idiom" : "universal",
1616
"scale" : "3x"
1717
}
1818
],
1919
"info" : {
20-
"version" : 1,
21-
"author" : "xcode"
20+
"author" : "xcode",
21+
"version" : 1
2222
}
2323
}
Loading
Loading
Loading

ios/Runner/Base.lproj/LaunchScreen.storyboard

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
1717
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1818
<subviews>
19-
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4">
20-
</imageView>
19+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" image="LaunchBackground" translatesAutoresizingMaskIntoConstraints="NO" id="tWc-Dq-wcI"/>
20+
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="YRO-k0-Ey4"></imageView>
2121
</subviews>
2222
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2323
<constraints>
24-
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="1a2-6s-vTC"/>
25-
<constraint firstItem="YRO-k0-Ey4" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="4X2-HB-R7a"/>
24+
<constraint firstItem="YRO-k0-Ey4" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="3T2-ad-Qdv"/>
25+
<constraint firstItem="tWc-Dq-wcI" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="RPx-PI-7Xg"/>
26+
<constraint firstItem="tWc-Dq-wcI" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="SdS-ul-q2q"/>
27+
<constraint firstAttribute="trailing" secondItem="tWc-Dq-wcI" secondAttribute="trailing" id="Swv-Gf-Rwn"/>
28+
<constraint firstAttribute="trailing" secondItem="YRO-k0-Ey4" secondAttribute="trailing" id="TQA-XW-tRk"/>
29+
<constraint firstItem="YRO-k0-Ey4" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="duK-uY-Gun"/>
30+
<constraint firstItem="tWc-Dq-wcI" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="kV7-tw-vXt"/>
31+
<constraint firstItem="YRO-k0-Ey4" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="xPn-NY-SIU"/>
2632
</constraints>
2733
</view>
2834
</viewController>
@@ -32,6 +38,7 @@
3238
</scene>
3339
</scenes>
3440
<resources>
35-
<image name="LaunchImage" width="168" height="185"/>
41+
<image name="LaunchImage" width="564" height="936"/>
42+
<image name="LaunchBackground" width="1" height="1"/>
3643
</resources>
3744
</document>

ios/Runner/Info.plist

+48-46
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
4-
<dict>
5-
<key>CFBundleDevelopmentRegion</key>
6-
<string>$(DEVELOPMENT_LANGUAGE)</string>
7-
<key>CFBundleExecutable</key>
8-
<string>$(EXECUTABLE_NAME)</string>
9-
<key>CFBundleIdentifier</key>
10-
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11-
<key>CFBundleInfoDictionaryVersion</key>
12-
<string>6.0</string>
13-
<key>CFBundleName</key>
14-
<string>$(BUNDLE_NAME)</string>
15-
<key>CFBundlePackageType</key>
16-
<string>APPL</string>
17-
<key>CFBundleShortVersionString</key>
18-
<string>$(FLUTTER_BUILD_NAME)</string>
19-
<key>CFBundleSignature</key>
20-
<string>????</string>
21-
<key>CFBundleVersion</key>
22-
<string>$(FLUTTER_BUILD_NUMBER)</string>
23-
<key>LSRequiresIPhoneOS</key>
24-
<true/>
25-
<key>UILaunchStoryboardName</key>
26-
<string>LaunchScreen</string>
27-
<key>UIMainStoryboardFile</key>
28-
<string>Main</string>
29-
<key>CFBundleDisplayName</key>
30-
<string>$(BUNDLE_DISPLAY_NAME)</string>
31-
<key>UISupportedInterfaceOrientations</key>
32-
<array>
33-
<string>UIInterfaceOrientationPortrait</string>
34-
<string>UIInterfaceOrientationLandscapeLeft</string>
35-
<string>UIInterfaceOrientationLandscapeRight</string>
36-
</array>
37-
<key>UISupportedInterfaceOrientations~ipad</key>
38-
<array>
39-
<string>UIInterfaceOrientationPortrait</string>
40-
<string>UIInterfaceOrientationPortraitUpsideDown</string>
41-
<string>UIInterfaceOrientationLandscapeLeft</string>
42-
<string>UIInterfaceOrientationLandscapeRight</string>
43-
</array>
44-
<key>UIViewControllerBasedStatusBarAppearance</key>
45-
<false/>
46-
<key>CADisableMinimumFrameDurationOnPhone</key>
47-
<true/>
48-
</dict>
49-
</plist>
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(BUNDLE_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>$(FLUTTER_BUILD_NAME)</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>$(FLUTTER_BUILD_NUMBER)</string>
23+
<key>LSRequiresIPhoneOS</key>
24+
<true/>
25+
<key>UILaunchStoryboardName</key>
26+
<string>LaunchScreen</string>
27+
<key>UIMainStoryboardFile</key>
28+
<string>Main</string>
29+
<key>CFBundleDisplayName</key>
30+
<string>$(BUNDLE_DISPLAY_NAME)</string>
31+
<key>UISupportedInterfaceOrientations</key>
32+
<array>
33+
<string>UIInterfaceOrientationPortrait</string>
34+
<string>UIInterfaceOrientationLandscapeLeft</string>
35+
<string>UIInterfaceOrientationLandscapeRight</string>
36+
</array>
37+
<key>UISupportedInterfaceOrientations~ipad</key>
38+
<array>
39+
<string>UIInterfaceOrientationPortrait</string>
40+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
41+
<string>UIInterfaceOrientationLandscapeLeft</string>
42+
<string>UIInterfaceOrientationLandscapeRight</string>
43+
</array>
44+
<key>UIViewControllerBasedStatusBarAppearance</key>
45+
<false/>
46+
<key>CADisableMinimumFrameDurationOnPhone</key>
47+
<true/>
48+
<key>UIStatusBarHidden</key>
49+
<false/>
50+
</dict>
51+
</plist>

lib/main.dart

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:flutter/material.dart';
4+
import 'package:flutter_native_splash/flutter_native_splash.dart';
45
import 'package:flutter_screenutil/flutter_screenutil.dart';
56
import 'package:flutter_template/core/common/config.dart';
67
import 'package:flutter_template/core/common/logger.dart';
@@ -9,8 +10,11 @@ import 'package:flutter_template/ui/main/main_screen.dart';
910

1011
Future main() async {
1112
await runZonedGuarded(() async {
13+
final widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
14+
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
1215
await _initSdks();
1316
runApp(const MyApp());
17+
FlutterNativeSplash.remove();
1418
}, (exception, stackTrace) async {
1519
await Logger.fatal(error: exception, stackTrace: stackTrace);
1620
});

0 commit comments

Comments
 (0)