- Add const constructors to @immutable classes (5 issues: prefer_const_constructors_in_immutables) - Fix nullable value casts in firesApi.dart (3 issues: cast_nullable_to_non_nullable) - Remove redundant default argument values (2 issues: avoid_redundant_argument_values) - Make YourLocation immutable with final fields (2 issues: avoid_equals_and_hash_code_on_mutable_classes) - Update imports and fix formatting Reduces lint issues from 129 to 106. APK builds successfully (146 MB).
86 lines
2.4 KiB
Dart
86 lines
2.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:meta/meta.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'dart:async';
|
|
|
|
@immutable
|
|
abstract class MaterialAppWithIntro extends StatelessWidget {
|
|
const MaterialAppWithIntro(this.name, this.theme, this.routes,
|
|
this.introWidget, this.continueWidget, this.prefsKey);
|
|
|
|
final String name;
|
|
final ThemeData theme;
|
|
final Map<String, WidgetBuilder> routes;
|
|
final WidgetBuilder introWidget;
|
|
final WidgetBuilder continueWidget;
|
|
final String prefsKey;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: MaterialAppWithIntroHome(introWidget, continueWidget, prefsKey),
|
|
title: name,
|
|
theme: theme,
|
|
routes: routes,
|
|
);
|
|
}
|
|
}
|
|
|
|
class MaterialAppWithIntroHome extends StatefulWidget {
|
|
const MaterialAppWithIntroHome(
|
|
this.introWidget, this.continueWidget, this.prefsKey);
|
|
|
|
final WidgetBuilder introWidget;
|
|
final WidgetBuilder continueWidget;
|
|
final String prefsKey;
|
|
|
|
@override
|
|
_MaterialAppWithIntroState createState() =>
|
|
_MaterialAppWithIntroState(introWidget, continueWidget, prefsKey);
|
|
}
|
|
|
|
class _MaterialAppWithIntroState extends State<MaterialAppWithIntroHome> {
|
|
_MaterialAppWithIntroState(
|
|
this.introWidget, this.continueWidget, this.prefsKey);
|
|
|
|
final WidgetBuilder introWidget;
|
|
final WidgetBuilder continueWidget;
|
|
final String prefsKey;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
Timer(const Duration(milliseconds: 1000), () {
|
|
checkFirstStart();
|
|
});
|
|
}
|
|
|
|
// https://stackoverflow.com/questions/50654195/flutter-one-time-intro-screen
|
|
Future<void> checkFirstStart() async {
|
|
final String initialWizardKey = prefsKey;
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
final bool showInitialWizard = (prefs.getBool(initialWizardKey) ?? true);
|
|
|
|
if (showInitialWizard) {
|
|
await prefs.setBool(initialWizardKey, false);
|
|
if (mounted) {
|
|
await Navigator.of(context)
|
|
.pushReplacement(MaterialPageRoute<void>(builder: introWidget));
|
|
}
|
|
} else {
|
|
if (mounted) {
|
|
await Navigator.of(context)
|
|
.pushReplacement(MaterialPageRoute<void>(builder: continueWidget));
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
}
|