flutter_easy 2.0.0 copy "flutter_easy: ^2.0.0" to clipboard
flutter_easy: ^2.0.0 copied to clipboard

outdated

A common Flutter package.

flutter_easy

flutter_easy #

pub flutter license build

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

void main() {
  createEasyApp(
    initCallback: initApp,
    initView: initView,
    appBaseURLChangedCallback: () {
      showToast("current: $kBaseURLType");
      1.delay(() {
        main();
      });
    },
    completionCallback: () {
      runApp(createApp());
      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

const _localeKey = "locale";

Future<void> initApp() async {
  StorageUtil.setEncrypt("963K3REfb30szs1n");
  await UserStore.load();
  routesIsLogin = () => UserStore.store.getState().isLogin;
  configApi(null);
  lastStorageLocale = await getStorageString(_localeKey);
  colorWithBrightness = Brightness.dark;
}

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

class App extends StatefulWidget {
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  void initState() {
    onLocaleChange = (locale) async {
      logWTF("$locale");
      if (locale != null) {
        lastStorageLocale = "$locale";
        await setStorageString(_localeKey, lastStorageLocale);
      } else {
        lastStorageLocale = null;
        removeStorage(_localeKey);
      }
      setState(() {});
      await Future.delayed(Duration(milliseconds: 500));
      return;
    };
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return BaseApp(
      // home: Routes.routes.buildPage(Routes.root, null),
      onGenerateRoute: (RouteSettings settings) {
        return MaterialPageRoute<Object>(builder: (BuildContext context) {
          return Routes.routes.buildPage(settings.name, settings.arguments);
        });
      },
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        LocaleNamesLocalizationsDelegate(),
      ],
      supportedLocales: S.delegate.supportedLocales,
      locale: lastLocale,
      localeResolutionCallback:
          (Locale locale, Iterable<Locale> supportedLocales) {
        logWTF("localeResolutionCallback: $locale");
        if (lastLocale == null || !S.delegate.isSupported(locale)) {
          return null;
        }
        return locale;
      },
    );
  }
}

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';