Skip to content

dangngocduc/flutter_application

Repository files navigation

flutter_application

This template base on Flutter 2.10.3

Structure

  • assets
    • icons: start with ic_
    • images: start with image_
  • lib
    • data
      • datasource: Data provider
        • local :
        • remote : API service
      • dto: Model Data, suffix: _dto
      • repositories: implement of repository interface on domain layer
    • gen: Gen Assets Management
    • domain
      • entity: Model interface, suffix: _model
      • repository: repository interface
    • ui
      • blocs: Bloc on this application
      • pages: Screen, Page of Application, suffix: _page
      • widgets: Component reuse on this app, suffix: _widget
    • utils
    • application.dart: MaterialApp of this app
    • initialize_dependencies.dart: init dependencies global as local service, bloc, domain repository
    • main.dart

Dependencies

Init all dependencies global on initialize_dependencies.dart

example: LocalService, Repository_ of domain layer.

Resource Manager

https://pub.dev/packages/flutter_gen

Homebrew

Works with MacOS and Linux.

$ brew install FlutterGen/tap/fluttergen

Pub Global

Works with MacOS, Linux and Windows.

$ dart pub global activate flutter_gen

Generate Model and State

$ flutter pub run build_runner build

Extension

path: lib/utils/extensions.dart

BuildContext

extension StateExtensions on State {
  ThemeData get theme => Theme.of(context);

  TextTheme get textTheme => Theme.of(context).textTheme;

  TextTheme get primaryTextTheme => Theme.of(context).primaryTextTheme;

  TextTheme get accentTextTheme => Theme.of(context).accentTextTheme;

  ColorScheme get colorScheme => Theme.of(context).colorScheme;

  MediaQueryData get mediaQueryData => MediaQuery.of(context);

  Size get size => MediaQuery.of(context).size;
}

State

extension ContextExtensions on BuildContext {
  ThemeData get theme => Theme.of(this);

  TextTheme get textTheme => Theme.of(this).textTheme;

  TextTheme get primaryTextTheme => Theme.of(this).primaryTextTheme;

  TextTheme get accentTextTheme => Theme.of(this).accentTextTheme;

  ColorScheme get colorScheme => Theme.of(this).colorScheme;

  MediaQueryData get mediaQueryData => MediaQuery.of(this);

  Size get size => MediaQuery.of(this).size;
}

Utils

Generate quick import file for a folder

1, Edit path of folder need gen quick import

# Change Folder At Here
genQuickImport lib/domain

2, run shell gen_quick_import.sh

 bash gen_quick_import.sh

Generate Model

 bash gen.sh

Release App

Change Icon App

Update icon : assets/images/icon_app.png

run:

[fvm] flutter pub run flutter_launcher_icons:main

Change splash Page on Native

(https://pub.dev/packages/flutter_native_splash)

[fvm] flutter pub run flutter_native_splash:create --path=flutter_native_splash.yaml

CI/CD

This project is config CI/CD with Github Action and build release only for Android.

Work flow:

.github/workflows/dart.yml

##Config build flavor

  • Flutter command: For Android setup:
    flutter build apk --no-shrink --flavor development --dart-define=FLAVOR=development --target lib/main.dart
    flutter build apk --no-shrink --flavor development --dart-define=FLAVOR=staging --target lib/main.dart
    flutter build apk --no-shrink --flavor development --dart-define=FLAVOR=production --target lib/main.dart

    flutter build apk --no-shrink --flavor staging --dart-define=FLAVOR=development --target lib/main.dart
    flutter build apk --no-shrink --flavor staging --dart-define=FLAVOR=staging --target lib/main.dart
    flutter build apk --no-shrink --flavor staging --dart-define=FLAVOR=production --target lib/main.dart

    flutter build apk --no-shrink --flavor production --dart-define=FLAVOR=development --target lib/main.dart
    flutter build apk --no-shrink --flavor production --dart-define=FLAVOR=staging --target lib/main.dart
    flutter build apk --no-shrink --flavor production --dart-define=FLAVOR=production --target lib/main.dart

For IOS:

    flutter build ios --flavor development --dart-define=FLAVOR=development --target lib/main.dart
    flutter build ios --flavor development --dart-define=FLAVOR=staging --target lib/main.dart
    flutter build ios --flavor development --dart-define=FLAVOR=production --target lib/main.dart
    
    flutter build ios --flavor staging --dart-define=FLAVOR=staging --target lib/main.dart 
    flutter build ios --flavor staging --dart-define=FLAVOR=development --target lib/main.dart
    flutter build ios --flavor staging --dart-define=FLAVOR=production --target lib/main.dart
        
    flutter build ios --flavor production --dart-define=FLAVOR=development --target lib/main.dart
    flutter build ios --flavor production --dart-define=FLAVOR=staging --target lib/main.dart
    flutter build ios --flavor production --dart-define=FLAVOR=production --target lib/main.dart

##Flutter support multi language

  • Use flutter intl and flutter_localizations