todos-contra-el-fuego-mobile/lib/widgets/material_app_with_intro.dart
vjrj 30a89fc5c0 Fix 13 lint issues: immutability, imports, async/await, and code style
High-priority fixes (10 issues):
- assignment_to_final errors (7): Use copyWith() to respect immutability in YourLocation, active_fires.dart, generic_map.dart, location_utils.dart, and fetch_data_middleware.dart instead of direct assignment
- Fixed import paths (3): Updated falsePositiveTypes.dart → false_positive_types.dart and firesApi.dart → fires_api.dart in reducers.dart, fire_notification_actions.dart, fires_api.dart

Medium/Low priority fixes (3 issues):
- unnecessary_non_null_assertion: Removed redundant '!' in app_intro_page.dart line 54
- use_super_parameters: Updated app_intro_page.dart to use modern super(key: key) syntax
- no_logic_in_create_state: Fixed material_app_with_intro.dart by moving parameters to State instead of createState
- noop_primitive_operations: Removed redundant .toString() in string interpolation
- avoid_void_async: Changed void _selectLocation to Future<void> in places_autocomplete_utils.dart
- avoid_dynamic_calls: Fixed dynamic map access in fires_api.dart by properly casting intermediate values

Result: Reduced lint issues from 56 to 20 (all remaining are by-design: library_private_types_in_public_api and implementation_imports from external packages)
APK builds successfully with no errors.
2026-03-12 09:16:20 +01:00

95 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
_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(),
),
);
}
}