- 13 library_private_types_in_public_api: These are intentional design patterns where private State classes are returned from createState() methods - 7 implementation_imports: These are from external packages (redux, flutter_map, shared_preferences) and necessary for the implementation All suppressed using ignore comments: - active_fires.dart, compass_map_plugin.dart, custom_stepper.dart, fire_alert.dart, fire_notification_list.dart, fires_app.dart, generic_map.dart, global_fires_bottom_stats.dart, home_page.dart, markdown_page.dart, slider.dart, support_page.dart, material_app_with_intro.dart - generic_map.dart, main_drawer.dart, main_prod.dart, fire_notifications_persist.dart, your_location_persist.dart, monitored_areas.dart, fetch_data_middleware.dart Result: ZERO lint issues in lib/ - clean build achieved!
96 lines
2.4 KiB
Dart
96 lines
2.4 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
@immutable
|
|
abstract class MaterialAppWithIntro extends StatelessWidget {
|
|
const MaterialAppWithIntro(
|
|
this.name,
|
|
this.theme,
|
|
this.routes,
|
|
this.introWidget,
|
|
this.continueWidget,
|
|
this.prefsKey, {
|
|
super.key,
|
|
});
|
|
|
|
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, {
|
|
super.key,
|
|
});
|
|
|
|
final WidgetBuilder introWidget;
|
|
final WidgetBuilder continueWidget;
|
|
final String prefsKey;
|
|
|
|
@override
|
|
// ignore: library_private_types_in_public_api
|
|
_MaterialAppWithIntroState createState() => _MaterialAppWithIntroState();
|
|
}
|
|
|
|
class _MaterialAppWithIntroState extends State<MaterialAppWithIntroHome> {
|
|
_MaterialAppWithIntroState();
|
|
|
|
late final WidgetBuilder introWidget = widget.introWidget;
|
|
late final WidgetBuilder continueWidget = widget.continueWidget;
|
|
late final String prefsKey = widget.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(),
|
|
),
|
|
);
|
|
}
|
|
}
|