Essentials

App

Base Controller

  • Path: root/lib/vaahextendflutter/base/base_controller.dart

Base Controller is used for initializing all core functionalities needed by vaahextendflutter.

...

Future<void> init({
  required Widget app,
  FirebaseOptions? firebaseOptions,
}) async {
  // Storage initialization to store some properties locally
  await GetStorage.init();

  // Environment initialization
  EnvironmentConfig.setEnvConfig();
  final EnvironmentConfig config = EnvironmentConfig.getEnvConfig();

  // Initialization of Firebase and Services
  if (firebaseOptions != null) {
    await Firebase.initializeApp(
      options: firebaseOptions,
    );
    DynamicLinks.init();
  }

  // Other Local Initializations (Depends on your app)
  AppTheme.init();
  Api.init();

  // Sentry Initialization (And/ Or) Running main app
  if (null != config.sentryConfig && config.sentryConfig!.dsn.isNotEmpty) {
    await SentryFlutter.init(
      (options) => options
        ..dsn = config.sentryConfig!.dsn
        ..autoAppStart = config.sentryConfig!.autoAppStart
        ..tracesSampleRate = config.sentryConfig!.tracesSampleRate
        ..enableAutoPerformanceTracing = config.sentryConfig!.enableAutoPerformanceTracing
        ..enableUserInteractionTracing = config.sentryConfig!.enableUserInteractionTracing
        ..environment = config.envType,
    );
    Widget child = app;
    if (config.sentryConfig!.enableUserInteractionTracing) {
      child = SentryUserInteractionWidget(
        child: child,
      );
    }
    if (config.sentryConfig!.enableAssetsInstrumentation) {
      child = DefaultAssetBundle(
        bundle: SentryAssetBundle(
          enableStructuredDataTracing: true,
        ),
        child: child,
      );
    }
    // Running main app
    runApp(child);
  } else {
    // Running main app when sentry config is not there
    runApp(app);
  }
}

Main function

  • Path: root/lib/main.dart

In the main function, we need to initialize the BaseController.

...

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  BaseController baseController = Get.put(BaseController());
  await baseController.init(
    app: const AppConfig(),
    // If you have configured firebase correctly for your app, pass firebase options here
  ); // Pass main app as argument in init method
}

More documentation about firebase.

Mateial App GetMaterialApp

final _navigatorKey = GlobalKey<NavigatorState>();

class AppConfig extends StatelessWidget {
  const AppConfig({super.key});

  @override
  Widget build(BuildContext context) {
    EnvironmentConfig config = EnvironmentConfig.getEnvConfig();
    return GetMaterialApp(
      title: config.appTitle,
      theme: ThemeData(
        primarySwatch: AppTheme.colors['primary'],
      ),
      onGenerateRoute: routeMiddleware,
      builder: (BuildContext context, Widget? child) {
        return DebugWidget(
          navigatorKey: _navigatorKey,
          child: child!,
        );
      },
    );
  }
}

Copyright © 2024