Flutter Easy Getx Implementations .

Overview

Flutter Easy GetX

Description

People ask me how I manage state,dependency,routes etc when I work with flutter,Here is the Simple Brief About GetX which I used for Dummy Basic Ecommerce Concept based flutter app development . Here I cover

  • State Management
  • Route Management
  • Dependency Management
  • Internationalization
  • Storage

Getting Started

Dependencies

dependencies: get: ^4.3.0

get_storage: ^2.0.3

Installing

  • flutter pub add get

Executing program

  • State Management
class Purchase extends GetxController {
  var products = <Product>[].obs;
  .........
 

obs to observe the products that can be changed. similarly when any user will do add to cart it needs to be observed so

class DemoController extends GetxController {
  var cartItems = <Product>[].obs;
  int get cartCount => cartItems.length;
   

For More Check Out the Controller and Home.dart and Demo.dart

  • Route Management

Initialize the routes in main.dart

  routes: {
          //routes for named navigation
          '/': (context) => HomePage(),
          '/cart': (context) => DemoPage(),
        },
        
        -------
 

Now You can called By named route using getX.

  IconButton(
                      onPressed: () => Get.toNamed('/cart',
                          arguments:
                              "Home Page To Demo Page -> Passing arguments"), //sending arguments 
                      icon: Icon(
                        Icons.arrow_forward_ios_rounded,
                        color: Colors.white,
                      ))
     ......
 

  • Dependency Management handle controller for Dependency Injection (Controller).
 
  final var ctrl = Get.put(DemoController());
  .......
 

After you add this once in your project you can find it out , you dont need to re connect it again and again Just Use Get.find()

 
 final DemoController ctrl = Get
      .find(); //getting the cart controller , you can show amount or anything
  .......
 

  • Internationalization

Change Theme or Language Easily . here is the demo main.dart

 
void main() async {
  await GetStorage.init();
  runApp(MyApp());
}


class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  final DemoController ctrl = Get.put(DemoController());
  @override
  Widget build(BuildContext context) {
    return SimpleBuilder(builder: (_) {
      // for darkmode instant change
      return GetMaterialApp(
        //for navigation dont forget to use GetMaterialApp
        title: 'Easy GetX',
        theme: ctrl.theme,
        debugShowCheckedModeBanner: false,
        initialRoute: '/',
        routes: {
          //routes for named navigation
          '/': (context) => HomePage(),
          '/cart': (context) => DemoPage(),
        },
      );
    });
  }
}

 

in the controller End :

 
 bool get isDark => storage.read('darkmode') ?? false;
  ThemeData get theme => isDark ? ThemeData.dark() : ThemeData.light();
  void changeTheme(bool val) => storage.write('darkmode', val);

  .......
 

to trigger it from anywhere [Checkout the DemoPage.dart file]

SwitchListTile(
              value: ctrl.isDark,
              title: Text("Touch to change ThemeMode"),
              onChanged: ctrl.changeTheme,
            ),
  .......
 

  • Storage [alternative of shared preference] Just need to Write GetStorage();
  final storage = GetStorage();
  bool get isDark => storage.read('darkmode') ?? false;
  ThemeData get theme => isDark ? ThemeData.dark() : ThemeData.light();
  void changeTheme(bool val) => storage.write('darkmode', val);

Help

If you need any help regarding this

Thanks

You might also like...

Flutter starter - GetX Flutter Firebase Auth Example

Flutter starter - GetX Flutter Firebase Auth Example

GetX Flutter Firebase Auth Example UPDATE: Version 2.0.0 Changed to new language

Jan 5, 2023

Pokedex-Flutter - Pokedex demonstrates modern Flutter development with GetX, Hive, Flow, Adaptive/Responsive Design

Pokedex-Flutter - Pokedex demonstrates modern Flutter development with GetX, Hive, Flow, Adaptive/Responsive Design

Pokedex-Flutter Pokedex demonstrates modern Flutter development with GetX, Hive,

Aug 17, 2022

Coffee flutter - A coffee app Used Firestore, GetX, flutter hooks, Provider

Coffee flutter - A coffee app Used Firestore, GetX, flutter hooks, Provider

coffee_flutter A Coffee Flutter project. Used Firestore, GetX, flutter_hooks, Pr

Oct 26, 2022

This is a simple flutter project of mine that i was trying to learn state managment in flutter with GetX.

managment This is my flutter project about state managment with GetX Getting Started This project is a starting point for a Flutter application. A few

Jul 9, 2022

Flutter Getx Template

This is source flutter template use getx for statemanagement ☕

Oct 18, 2022

Garreta project using Flutter and GetX

garreta A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Jun 3, 2021

This repo is a boilerplate to create flutter application easily. It is based on **GetX**.

This repo is a boilerplate to create flutter application easily. It is based on **GetX**.

flutter-app boilerplate This repo is a boilerplate to create flutter application easily. It is based on GetX. More info about GetX here. The app has b

Dec 3, 2022

flutter 2.x and getx v4.x template

flutter_getx_template Language: 中文简体 | English 基于getx 实现的全新flutter getx 模版,适用于中大型项目的开发。 💥 flutter最新版本的空安全 🍀 view 和 逻辑 完全解耦 ⚡ view 和 state 自动响应 📦 di

Dec 19, 2022

Boilerplate for Flutter + GetX MVVM

flutter_getx_boilerplate A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you

May 31, 2022
Owner
Tasnuva Tabassum oshin
Mobile Application Developer.Living In Dhaka Bangladesh. Visit : https://www.facebook.com/tasnuva.oshin12
Tasnuva Tabassum oshin
A flutter package uses native implementations to resize an image

fast_image_resizer This package uses native implementations to resize an image.

Soeren Schoenbrod 0 Dec 20, 2021
100+ Professional UI implementations with Code in Flutter. Available in Android, iOS, Linux and Web

Flutter UI Challenges My effort on replicating various apps UI on flutter. View on Web Building and running the code [ Updated ] Thank you all for you

Damodar Lohani 4k Dec 28, 2022
Morphing Coffee 0 Jan 27, 2022
Flutter-GetX-Toturials - Getx full tutorials for flutter

getx_full_tutorials A new Flutter getx tutorial. This Project Contains: Snackbar

Inzimam Bhatti 2 Dec 1, 2022
Flutter getx template - A Flutter Template using GetX package for State management, routing and Dependency Injection

Flutter GetX Template (GetX, Dio, MVVM) This Flutter Template using GetX package

Tareq Islam 6 Aug 27, 2022
constructing... Flutter, Ganache, Truffle, Remix, Getx Pattern, Infura, GetX, Blockchain

constructing... Flutter, Ganache, Truffle, Remix, Getx Pattern, Infura, GetX, Blockchain

Kauê Murakami 20 Dec 20, 2022
A basic boilerplate template for starting a Flutter GetX project. GetX, Dio, MVVM, get CLI, Localization, Pagination etc are implemented.

Flutter GetX Template (GetX, Dio, MVVM) This Flutter Template using GetX package for State management, routing and Dependency Injection (bindings). We

Hasan Abdullah 214 Jan 9, 2023
Flutter GetX Template (GetX, Dio, MVVM)

Flutter GetX Template (GetX, Dio, MVVM) This Flutter Template using GetX package for State management, routing and Dependency Injection (bindings). We

null 7 Dec 18, 2022
A flutter widget to indicate loading progress. Easy to use, easy to extend

?? ?? ?? A flutter widget to indicate loading progress. Easy to use, easy to extend

Manuel Duarte 2 May 30, 2022