Integrate Monday Hero to your Existing Project

Manually add dependencies and sync code for integration

If you already have a Flutter project, you can integrate it into Monday Hero by manually installing the dependencies in your workspace. After you complete the instructions on this page, use the sync function as explained on the next page. Monday Hero will automatically create the missing folders/files.

Setting Up The Localization Requirements

MHLocalizationAssetLoader is an essential custom asset loader for managing app-specific localization files and Monday Hero-generated localization files. This allows translation files under both assets/translations and assets/translations/mh_generated to be used in the app and managed separately.

Step 1: Add the 'easy_localization' package in your pubspec.yaml and complete installation by executing the following command in your project root. Check out the package documentation for more information if needed.

flutter pub add easy_localization

Step 2: Declare your asset directories in the pubspec.yaml file.

assets:
    #Localization Files
    - assets/translations/
    # Localization Files generated by Monday Hero
    - assets/translations/mh_generated/
    - assets/images/

Step 3: Navigate to the file where your project's main() function is located. By default, this is the main.dart file. Add the following imports:

import 'package:easy_localization/easy_localization.dart';
import 'core/localization/mh_localization_asset_loader.dart';

Step 4: Call 'await EasyLocalization.ensureInitialized();' in your main function.

  • Set the path as 'assets/translations'

  • Set assetLoader as const MHLocalizationAssetLoader()

  • Set child as your app instance.

Sample Configuration:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  runApp(
    EasyLocalization(
      supportedLocales: const [
        Locale('en', 'US'),
      ],
      path: 'assets/translations',
      assetLoader: const MHLocalizationAssetLoader(),
      fallbackLocale: const Locale('en', 'US'),
      child: const MyApp(),
    ),
  );
}

Setting Up The App Router

Flutter features an idiomatic declarative routing mechanism similar to the build methods used with widgets. To implement this mechanism in your projects with Monday Hero, you need to adjust your app definition from the MaterialApp() widget.

Step 1: Navigate to your app definition and delete the home value if your app has one.

Step 2: Set initialRoute and onGenerateRoute as follows:

MaterialApp(
   // ...
   initialRoute: AppRoutes.init,
   onGenerateRoute: (settings) => AppRouter.generateRoute(settings),
   // ...
    )

You're all set! Next, synchronize the project with your local directory to obtain the missing folders and files.

Last updated