Saltar al contenido

ejemplo de código de valor de escucha flutter getx

Después de consultar expertos en la materia, programadores de varias áreas y maestros dimos con la solución al problema y la compartimos en este post.

Ejemplo 1: getx flutter

// Create controller class and extends GetxControllerclassControllerextendsGetxControllerint counter =0;voidincrement()
    counter++;update();// use update() to update counter variable on UI when increment be called// On your Stateless/Stateful class, use GetBuilder to update Text when increment be called 
GetBuilder<Controller>(init:Controller(),// INIT IT ONLY THE FIRST TIMEbuilder:(_)=>Text('$_.counter',),)//Initialize your controller only the first time. The second time you are using ReBuilder for the same controller, do not use it again. Your controller will be automatically removed from memory as soon as the widget that marked it as 'init' is deployed. You don't have to worry about that, Get will do it automatically, just make sure you don't start the same controller twice.

Ejemplo 2: obtener paquete flutter

class Home extendsStatelessWidgetfinal controller = Get.put(Controller());
  @override
  Widget build(BuildContext context)returnScaffold(appBar:AppBar(title:Text("counter")),body:Center(child:Column(mainAxisAlignment: MainAxisAlignment.center,children:[
            GetBuilder<Controller>(builder:(_)=>Text('clicks: $controller.count',)),RaisedButton(child:Text('Next Route'),onPressed:()
                Get.to(Second());,),],),),floatingActionButton:FloatingActionButton(child:Icon(Icons.add),onPressed: controller.increment(),),);classSecondextendsStatelessWidgetfinal Controller ctrl = Get.find();
  @override
  Widget build(context)returnScaffold(body:Center(child:Text("$ctrl.count")));

valoraciones y comentarios

Acuérdate de que te damos el privilegio parafrasear si diste con el hallazgo.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *