Introduction

After a Flutter update, many of your packages will break. Sometimes compilation errors happen. Get centralizes the main resources for development (State, dependency, and route management), allowing you to add a single package to your pubspec, and start working. The only thing you need to do is update the Get dependency.

Getx is unorthodox with the standard approach, and while it does not completely ban the use of StatefulWidgets, InitState, etc., it always has a similar approach that can be cleaner. Controllers have life cycles, and when you need to make an API REST request, for example, you don’t depend on anything in the view. You can use onInit to initiate the Http call, and when the data arrives, the variables will be populated. As GetX is fully reactive (really, and works under streams), once the items are filled, all widgets that use that variable will be automatically updated in the view.


Installation

Add Get to your pubspec.yaml file:

dependencies:
  get:

Import get in files that will be used:

import 'package:get/get.dart';

The Trident of GetX

  • State Management
  • Route Management
  • Dependency Management

State Management

Currently, there are several state management for a flutter. Get isn’t better or worse than any other state manager, you can choose whatever you are comfortable with. and not the enemy of others.

Get has two different state managers:

  • Simple state manager (known as GetBuilder).
  • Reactive state manager (known as GetX).

Simple State Manager

Get has a state manager that is extremely light and easy GetBuilder.

You don’t need StatefulWidgets anymore.

Using StatefulWidgets means storing the state of entire screens unnecessarily, The StatefulWidget class is a class larger than StatelessWidget, which will allocate more RAM, and this may not make a significant difference between one or two classes, but it will most certainly do when you have 100 of them!

Unless you need to use a mixin, like TickerProviderStateMixin, it will be totally unnecessary to use a StatefulWidget with Get.

You can call all methods of a StatefulWidget directly from a GetBuilder. If you need to call initState() or dispose() method, for example, you can call them directly;

GetBuilder<Controller>(
  initState: (_) => Controller.to.fetchApi(),
  dispose: (_) => Controller.to.closeStreams(),
  builder: (s) => Text('${s.username}'),
),

#flutter #mobile-apps

GetX In Flutter
126.60 GEEK