flutter_easy

A common Flutter package.

Getting Started

Additional arguments:

--dart-define=app-debug-flag=true

Run:

flutter run --release --dart-define=app-debug-flag=true

Example:

main.dart

createEasyApp(
    initCallback: initApp,
    initView: initView,
    appBaseURLChangedCallback: () {
      // Reload API
      configAPI(null);
    },
    completionCallback: () {
      runApp(App());
      if (isAndroid) {
        SystemChrome.setPreferredOrientations([
          DeviceOrientation.portraitUp,
          DeviceOrientation.portraitDown,
        ]);
        // Set overlay style status bar. It must run after MyApp(), because MaterialApp may override it.
        SystemUiOverlayStyle systemUiOverlayStyle =
            SystemUiOverlayStyle(statusBarColor: Colors.transparent);
        SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
      }
    },
  );

app.dart

Future<void> initApp() async {
  StorageUtil.setEncrypt("963K3REfb30szs1n");
  await Get.putAsync(() => UserService().load());
  configApi(null);
  colorWithBrightness = Brightness.dark;
}

Widget get initView {
  return BaseLaunchLocal(
    child: Image.asset(assetsImagesPath("launch/flutter_logo_color")),
  );
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseApp(
      initialRoute: Routes.splash,
      getPages: Routes.routes,
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        LocaleNamesLocalizationsDelegate(),
      ],
      supportedLocales: S.delegate.supportedLocales,
      locale: Get.deviceLocale,
      localeResolutionCallback:
          (Locale? locale, Iterable<Locale> supportedLocales) {
        logDebug("localeResolutionCallback: $locale");
        if (locale == null || !S.delegate.isSupported(locale)) {
          return null;
        }
        return locale;
      },
    );
  }
}

routes.dart

class Routes {
  static final String root = '/';
  static final String splash = '/splash';

  Routes._();

  static final List<GetPage> routes = [
    GetPage(
      name: Routes.root,
      page: () => RootPage(),
    ),
    GetPage(
      name: Routes.splash,
      page: () => SplashPage(),
    ),
    GetPage(
      name: routesLoginNamed,
      page: () => LoginPage(),
    ),
}

Installing

Add flutter_easy to your pubspec.yaml file:

dependencies:
  flutter_easy:

Import flutter_easy in files that it will be used:

import 'package:flutter_easy/flutter_easy.dart';

GitHub

https://github.com/OctMon/