Thursday, March 7, 2024

GetBuilder ( Simple Statemanagement ) with GetxController (Controller)

 GetBuilder ( Simple Statemanagement ) with GetxController (Controller)


1. Create Controller

import 'package:get/get_state_manager/get_state_manager.dart';

class SimpleManagementController extends GetxController{
var count =0;

void increment(){
count++;
update();
}
}


2. Calling GetBuilder

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx/controller/simplestatemanagement_controller.dart';

class SimpleStateManagementPage extends StatelessWidget {
SimpleStateManagementPage({
super.key});
// Create object or instance
final SimpleManagementController controller=Get.put(SimpleManagementController());

@override
Widget build(BuildContext context) {
return Scaffold(
appBar:
AppBar(
title:
Text("Get Builder"),
backgroundColor: Colors.
greenAccent,
),
body:
SafeArea(
child:
Column(
children: [
Text("Welcome"),
            // Calling variable
GetBuilder<SimpleManagementController>(
builder: (_)=>
Text("Clicks ${controller.count}")
),
],
),
),
floatingActionButton:
FloatingActionButton(
child:
Icon(Icons.add),
onPressed: (){
        // Calling function
controller.increment();
},
),
);
}
}

No comments:

Post a Comment

Featured post

Compress Image With Show File Size & Resolution in Flutter

 Compress Image With Show File Size & Resolution  1.Multiple File Image Compress with file Size import 'dart:io' ; import 'p...

LightBlog