Skip to content

Commit

Permalink
Keep splash screen visible until app is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed May 23, 2024
1 parent 8f4943d commit 6039eb3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:feedback_sentry/feedback_sentry.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -105,8 +106,9 @@ void initFlogger() {
}

void initFlutter() {
WidgetsFlutterBinding.ensureInitialized();
WidgetsBinding.instance.addObserver(WidgetBindingLogger());
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
widgetsBinding.addObserver(WidgetBindingLogger());
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding); // keeps the splash screen visible
}

class WidgetBindingLogger extends WidgetsBindingObserver {
Expand Down Expand Up @@ -195,8 +197,9 @@ class _TailAppState extends State<TailApp> {
child: ValueListenableBuilder(
valueListenable: SentryHive.box(settings).listenable(keys: [appColor]),
builder: (BuildContext context, value, Widget? child) {
Future(() => FlutterNativeSplash.remove()); //remove the splash screen one frame later
return MaterialApp.router(
title: subTitle(),
title: title(),
color: Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault)),
theme: buildTheme(Brightness.light, Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault))),
darkTheme: buildTheme(Brightness.dark, Color(SentryHive.box(settings).get(appColor, defaultValue: appColorDefault))),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ packages:
source: hosted
version: "0.7.1"
flutter_native_splash:
dependency: "direct dev"
dependency: "direct main"
description:
name: flutter_native_splash
sha256: edf39bcf4d74aca1eb2c1e43c3e445fd9f494013df7f0da752fefe72020eedc0
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies:
flutter_markdown: ^0.7.1
#video_player: ^2.8.6
fading_edge_scrollview: ^4.1.1
flutter_native_splash: ^2.4.0

# Dio HTTP
dio: ^5.4.3+1
Expand Down Expand Up @@ -117,7 +118,6 @@ dev_dependencies:
build_runner: # Required for build
flutter_lints: # Dryer Lint
riverpod_generator: ^2.4.2
flutter_native_splash: ^2.4.0
json_serializable: ^6.8.0 # required for @JsonSerializable annotations
hive_generator: ^2.0.1 # required for @HiveType annotations

Expand Down

0 comments on commit 6039eb3

Please sign in to comment.