Remove the external comunes-flutter library dependency and replace all its components with local implementations: - Utility functions: Created lib/utils/widget_utils.dart with compactWidgets() and ellipse() functions, replacing the comunes-flutter helpers with modern Dart null-safety patterns (whereType instead of where(notNull)) - Secret loader: Inlined as lib/utils/secret_loader.dart for loading JSON config - Layout widgets: Replaced CenteredRow/CenteredColumn with standard Row/Column with MainAxisAlignment.center - Intro screens: Copied AppIntroPage and MaterialAppWithIntro locally in lib/widgets/ with cleaned-up deprecated code patterns - Button widget: Created lib/widgets/rounded_btn.dart for the RoundedBtn used in activeFires.dart Changes span 20 files: - 5 new utility/widget files created - Updated imports in 15 files - Removed path dependency from pubspec.yaml - All functionality preserved, build verified with flutter pub get Impact: - Removes external dependency, simplifying project structure - Modern Dart patterns (proper null-safety) - Better code clarity with explicit widget properties - Easier onboarding (no 'what is comunes-flutter?' questions)
87 lines
3.2 KiB
Dart
87 lines
3.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
|
import 'package:redux/redux.dart';
|
|
|
|
import 'firesApp.dart';
|
|
import 'globals.dart' as globals;
|
|
import 'models/appState.dart';
|
|
import 'models/firesApi.dart';
|
|
import 'redux/fetchDataMiddleware.dart';
|
|
import 'redux/reducers.dart';
|
|
import 'sentryReport.dart';
|
|
import 'utils/secret_loader.dart';
|
|
|
|
Future<PackageInfo> loadPackageInfo() async {
|
|
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
|
return packageInfo;
|
|
}
|
|
|
|
Future<Map<String, dynamic>> loadSecrets() async {
|
|
return SecretLoader(
|
|
secretPath: globals.isDevelopment
|
|
? 'assets/private-settings-dev.json'
|
|
: 'assets/private-settings.json')
|
|
.load();
|
|
}
|
|
|
|
Future<void> mainCommon(List<Middleware<AppState>> otherMiddleware) async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// Initialize Firebase before any Firebase-dependent code runs
|
|
await Firebase.initializeApp();
|
|
|
|
final GetIt getIt = GetIt.instance;
|
|
getIt.registerSingleton<FiresApi>(FiresApi());
|
|
loadPackageInfo().then((PackageInfo packageInfo) {
|
|
globals.appVersion = packageInfo.version;
|
|
loadSecrets().then((Map<String, dynamic> secrets) {
|
|
final Store<AppState> store = Store<AppState>(appStateReducer,
|
|
initialState: AppState(
|
|
gmapKey: secrets['gmapKey'] as String,
|
|
firesApiKey: secrets['firesApiKey'] as String,
|
|
serverUrl: secrets['firesApiUrl'] as String,
|
|
firesApiUrl: "${secrets['firesApiUrl'] as String}api/v1/"),
|
|
middleware: List<Middleware<AppState>>.from(otherMiddleware)
|
|
..add(fetchDataMiddleware));
|
|
|
|
getIt.registerSingleton<Store<AppState>>(store);
|
|
getIt.registerSingleton<String>(store.state.firesApiUrl,
|
|
instanceName: 'firesApiUrl');
|
|
getIt.registerSingleton<String>(store.state.firesApiKey,
|
|
instanceName: 'firesApiKey');
|
|
getIt.registerSingleton<String>(store.state.serverUrl,
|
|
instanceName: 'serverUrl');
|
|
getIt.registerSingleton<String>(store.state.gmapKey,
|
|
instanceName: 'gmapKey');
|
|
|
|
// https://flutter.io/cookbook/maintenance/error-reporting/
|
|
runZonedGuarded<Future<void>>(() async {
|
|
runApp(FiresApp(store));
|
|
}, (Object error, StackTrace? stackTrace) {
|
|
// Whenever an error occurs, call the `_reportError` function. This will send
|
|
// Dart errors to our dev console or Sentry depending on the environment.
|
|
reportError(error, stackTrace ?? StackTrace.current);
|
|
});
|
|
|
|
// Listen to store changes, and re-render when the state is updated
|
|
store.onChange.listen((AppState state) {
|
|
// print('Store onChange');
|
|
});
|
|
FlutterError.onError = (FlutterErrorDetails details) {
|
|
if (!useSentry) {
|
|
// In development mode simply print to console.
|
|
FlutterError.dumpErrorToConsole(details);
|
|
} else {
|
|
// In production mode report to the application zone to report to
|
|
// Sentry.
|
|
Zone.current.handleUncaughtError(
|
|
details.exception, details.stack ?? StackTrace.current);
|
|
}
|
|
};
|
|
});
|
|
});
|
|
}
|