Get Builder With Unique id with Controller
1. Create Controller
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
class SimpleManagementController extends GetxController{
var count =0;
void increment(){
count++;
update(['123']);
}
}
2.Calling Unique Id
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:getx/controller/simplestatemanagement_controller.dart';
class SimpleStateManagementPage extends StatelessWidget {
SimpleStateManagementPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Get Builder"),
backgroundColor: Colors.greenAccent,
),
body: SafeArea(
child: SingleChildScrollView(
child: Column(
children: [
Text("Welcome"),
GetBuilder<SimpleManagementController>(
id: '123', // unique ID
init: SimpleManagementController(),
builder: (controller) => Text("Clicks ${controller.count}")
),
GetBuilder<SimpleManagementController>(
init: SimpleManagementController(),
builder: (controller) => Text("Clicks ${controller.count}")
),
],
),
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
var controller = Get.find<SimpleManagementController>();
controller.increment();
},
),
);
}
}
No comments:
Post a Comment