flutter getx template
- this is source flutter template use getx for statemanagement ☕
�� overview main.dart, after you can customize languages package, themes, pages and routes
import 'package:flutter/material.dart';
import 'package:flutter_postman_application/src/lang/translation_service.dart';
import 'package:flutter_postman_application/src/routes/app_pages.dart';
import 'package:flutter_postman_application/src/shared/logger/logger_utils.dart';
import 'package:flutter_postman_application/src/theme/theme_service.dart';
import 'package:flutter_postman_application/src/theme/themes.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
void main() async {
await getstorage.init();
runapp(getmaterialapp(
debugshowcheckedmodebanner: false,
enablelog: true,
logwritercallback: logger.write,
initialroute: apppages.initial,
getpages: apppages.routes,
locale: translationservice.locale,
fallbacklocale: translationservice.fallbacklocale,
translations: translationservice(),
theme: themes().lighttheme,
darktheme: themes().darktheme,
thememode: themeservice().getthememode(),
));
}
�������������� customize languages package
- translation_service.dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'en_us.dart';
import 'vi_vn.dart';
class translationservice extends translations {
static final locale = get.devicelocale;
static final fallbacklocale = locale('en', 'us');
@override
map<string, map<string, string>> get keys => {
'en_us': en_us,
'vi_vn': vi_vn,
};
}
- en_us.dart
const map<string, string> en_us = {
'helloword': 'hello world',
};
- �� similar to other language files
�� customize theme package
- themes.dart
import 'package:flutter/material.dart';
import 'package:flutter_postman_application/src/public/styles.dart';
class themes {
final lighttheme = themedata.light().copywith(
primarycolor: colorprimary,
appbartheme: appbartheme(
brightness: brightness.light,
texttheme: texttheme(
headline2: textstyle(color: colortitle),
),
),
);
final darktheme = themedata.dark().copywith(
primarycolor: colorprimary,
appbartheme: appbartheme(
brightness: brightness.dark,
texttheme: texttheme(
headline2: textstyle(color: mc),
),
),
);
}
�� save theme mode in device storage
- theme_service.dart
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:get/get.dart';
class themeservice {
final _getstorage = getstorage();
final storagekey = 'isdarkmode';
thememode getthememode() {
return issaveddarkmode() ? thememode.dark : thememode.light;
}
bool issaveddarkmode() {
return _getstorage.read(storagekey) ?? false;
}
void savethememode(bool isdarkmode) {
_getstorage.write(storagekey, isdarkmode);
}
void changethememode() {
get.changethememode(issaveddarkmode() ? thememode.light : thememode.dark);
savethememode(!issaveddarkmode());
}
}
</> log error for dev
- logger_utils.dart
class logger {
static void write(string text, {bool iserror = false}) {
future.microtask(() => print('** $text. iserror: [$iserror]'));
}
}
�� management routes
- app_routes.dart
part of 'app_pages.dart';
abstract class routes {
static const root = '/root';
static const home = '/home';
}
�� management pages
- app_pages.dart
import 'package:flutter_postman_application/src/app.dart';
import 'package:get/get.dart';
part 'app_routes.dart';
// ignore: avoid_classes_with_only_static_members
class apppages {
static const initial = routes.root;
static final routes = [
getpage(
name: routes.root,
page: () => app(),
children: [],
),
];
}
how i can run it?
- :rocket: flutter version < 2.0 (1.x.x), not support null safety
- :rocket: buy this source
- :rocket: run below code in terminal
flutter pub get
flutter run
lib use in project:
get_test: ^3.13.3
get_storage: ^1.4.0
author:
lambiengcode
Comments are closed.