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 = 
   
    [].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 = 
   
    [].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.

Passing arguments"), //sending arguments icon: Icon( Icons.arrow_forward_ios_rounded, color: Colors.white, )) ...... ">
  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...

Provider support for overlay, make it easy to build toast and In-App notification.

overlay_support Provider support for overlay, make it easy to build toast and In-App notification. this library support ALL platform Interaction If yo

Jan 1, 2023

A popup simple topModalSheet menu button widget with handsome design and easy to use

A popup simple topModalSheet menu button widget with handsome design and easy to use

top_modal_sheet A popup simple topModalSheet menu button widget with handsome design and easy to use. Installations Add top_modal_sheet: ^1.0.0 in you

Jul 29, 2022

Flutter package: Assorted layout widgets that boldly go where no native Flutter widgets have gone before.

Flutter package: Assorted layout widgets that boldly go where no native Flutter widgets have gone before.

assorted_layout_widgets I will slowly but surely add interesting widgets, classes and methods to this package. Despite the package name, they are not

Dec 22, 2022

Flutter Carousel Pro - A Flutter Carousel widget

Flutter Carousel Pro - A Flutter Carousel widget

Carousel Extended A Flutter Carousel widget. Usage As simple as using any flutter Widget. Based on Carousel Pro but extended to be able to navigate be

Dec 7, 2020

Flutter-useful-widgets - Flutter Useful Widgets

Flutter-useful-widgets - Flutter Useful Widgets

useful_widgets This package makes it easy to build apps by providing a list of simple and useful widgets. import 'package:useful_widgets/useful_widget

Jun 20, 2022

Flutter Duration Button - Create auto-click button likes Netflix's Skip Intro button in Flutter

Flutter Duration Button - Create auto-click button likes Netflix's Skip Intro button in Flutter

Flutter Duration Button - Create auto-click button likes Netflix's Skip Intro button in Flutter

Dec 7, 2022

Various Flutter widgets that are developed by Google but not by the core Flutter team

Flutter widgets This repository contains the source code for various Flutter widgets that are developed by Google but not by the core Flutter team. Is

Jan 7, 2023

🟥 A flutter widget that flashes when flutter fails to render a frame in a certain timeframe

🟥 A flutter widget that flashes when flutter fails to render a frame in a certain timeframe

Oct 8, 2022

A Flutter plugin that makes it easier to make floating/overlay windows for Android with pure Flutter

A Flutter plugin that makes it easier to make floating/overlay windows for Android with pure Flutter

flutter_floatwing A Flutter plugin that makes it easier to make floating/overlay windows for Android with pure Flutter. Android only Features Pure Flu

Dec 21, 2022
Owner
Tasnuva Tabassum oshin
Mobile Application Developer.Living In Dhaka Bangladesh. Visit : https://www.facebook.com/tasnuva.oshin12
Tasnuva Tabassum oshin
A really easy to use flutter toast library

BotToast ?? A really easy to use flutter toast library! Language: English | 中文简体 ?? Overview ?? Online Demo ?? Example ?? Renderings ?? Getting starte

null 719 Dec 28, 2022
RFlutter Alert is super customizable and easy-to-use alert/popup dialogs for Flutter.

RFlutter Alert is super customizable and easy-to-use alert/popup dialogs for Flutter. You may create reusable alert styles or add buttons as much as you want with ease.

Ratel 362 Jan 1, 2023
📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget.

?? Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.

Blue Fire 1.7k Jan 7, 2023
A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate

A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.

Marcelo Glasberg 214 Dec 13, 2022
Flutter package: Easy and powerful internationalization using Dart extensions.

i18n_extension Non-boilerplate Translation and Internationalization (i18n) for Flutter Start with a widget with some text in it: Text("Hello, how are

Marcelo Glasberg 262 Dec 29, 2022
A Flutter Package for easy building dialogs

Easy Dialog package helps you easily create basic or custom dialogs. For extended documentation visit project pub package. Star ⭐ this repo if you lik

Ricardo Niño 39 Oct 14, 2022
This flutter package provides an easy implementation of a Slider Button to cancel current transaction or screen

This flutter package provides an easy implementation of a Slider Button to cancel current transaction or screen

null 222 Nov 8, 2022
A Simple and easy to use flutter package for showing progress bar.

progress_dialog A Simple and easy to use flutter package for showing progress bar. #Usage Import the package import 'package:custom_progress_dialog/cu

Vikas Jilla 6 May 23, 2022
SKAlertDialog - A highly customizable, powerful and easy-to-use alert dialog for Flutter.

SKAlertDialog A highly customizable, powerful and easy-to-use alert dialog for Flutter. GIF Screenshots SKAlertDialog Basic Alert Alert with buttons A

Senthil_Kumar 7 May 18, 2022
Flutter Color Picker Wheel - an easy to use widget which can be heavily customized

Flutter Color Picker Wheel Flutter Color Picker Wheel is an easy to use widget which can be heavily customized. You can use the WheelColorPicker direc

Kexin Lu 35 Oct 4, 2022