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

Libraries

adapt_util
base
base64_image
base_animation_image
base_animation_number_text
base_cycle_view
base_launch
base_progress_bar
base_refresh
base_tab_page
base_tag_list_view
color_util
crypto_util
date_util
duration_extensions
dynamic_extensions
export
export
export
flutter_easy
global_util
hw_html
hw_io
hw_mp
hw_none
json_util
keep_alive
loading_util
loading_view
locale_util
log_console
logger_util
lunar_calendar_converter
network_util
num_extensions
package_info_util
picker_util
placeholder_view
routes
shared_preferences_util
storage_util
string_extensions
string_util
timer_util
toast_util
uuid_util
web_image