FlutterCore make you get the most rapid development.
- MVVM Architecture
- Simplify API Callback
- Get Lifecycle
- Helper & Utilities
- Suggest more... lets contribute!
Read the CHANGELOG to find out what's included in the latest update!
Add this dependency to your package's pubspec.yaml (and run flutter pub get):
dependencies:
flutter_core:
git:
url: https://github.com/yzzzd/fluttercore.git
ref: {latest_release}
void main() {
runApp(const App());
}
class App extends CoreApp{
const App({super.key});
@override
Widget initialScreen() => const WelcomeScreen(); // initial screen goes here
@override
Bindings initialBinding() => AppBinding(); // initial binding dependency goes here
}
Your Screen
class should be extends from CoreScreen
to get View and ViewModel implementation
class HomeScreen extends CoreScreen<HomeViewModel> {
const HomeScreen({super.key});
@override
Widget buildScreen(BuildContext context) {
return Scaffold();
}
}
Also your ViewModel
class should be extends from CoreViewModel
. You will able to use update();
or Collectable<T>
data state.
class HomeViewModel extends CoreViewModel
// in ViewModel
Collectable<int> favorite = Collectable(0);
// do operation
favorite.value += 1;
// in Screen
Collect(() => Text('Total favorites: ${viewModel.favorite}'))
// OR
// in ViewModel
var favorite = 0;
// do operation
favorite += 1;
update();
// in Screen
CollectBuilder<HomeViewModel>(
builder: (viewModel) => Text('Total favorites: ${viewModel.favorite}')
)
// use CollectableList
CollectableList<Fruit> fruits = CollectableList([]);
// then you need call refresh() if you change value of Fruit / not the list
fruits[index].flavour = 'Sweet';
fruits.refresh();
// or you don't need to call refresh(), but you should use List data and call update(), then use Builder to update the Screen.
With wrapping CoreApp
before, then define the routes in getPages()
override.
@override
List<GetPage> getPages() => [
GetPage(
name: HomeScreen.routeName,
page: () => const HomeScreen(),
binding: BindingsBuilder(() {
Get.lazyPut(() => HomeViewModel());
})
),
GetPage(
name: LoginScreen.routeName,
page: () => const LoginScreen(),
binding: BindingsBuilder(() {
Get.lazyPut(() => LoginViewModel());
})
)
].toList();
To navigate to next screen
Get.toNamed('/ProductDetailScreen');
To navigate and remove the previous screen from the tree.
Get.offNamed('/HomeScreen');
To navigate and remove all previous screens from the tree.
Get.offAllNamed('/LoginScreen');
*MAY DEPRECATED* So please refer from CHANGELOG for latest way
Example of LoginResponse
extend from ApiResponse
which have basic respon api properties like: code
, message
. You can simply add the required properties following on your api response needs.
@JsonSerializable()
class LoginResponse extends ApiResponse {
@JsonKey(name: 'data')
User user;
}
@POST('/login')
Future<LoginResponse> login(
@Field('username') String username,
@Field('password') String password
);
ApiObserver.run<LoginResponse>(
api: () => _apiService.login(username, password),
onSuccess: (response) async {
await _userDao.saveLoginUser(response.user);
dismissDialog();
Get.offAllNamed(HomeScreen.routeName);
},
onError: (response) => showDialog(message: response.message)
);
FlutterCore still under beta development, any insight feel free to contact. Thanks.