“Holen Sie sich in Dart” Code-Antworten

Dart Getter

// getter: 		return_type get field_name {  }
String get emp_name { 
   return empName; 
} 
// setter:  	set field_name {  }
void set emp_name(String name) { 
   this.empName = name; 
} 
VasteMonde

Holen Sie sich in Dart

GetX is a useful widget when you want to inject the controller into 
the init property, or when you want to retrieve an instance of the controller within the widget itself. 
In other cases, you can insert your widget into an Obx, which receives a widget function. 
This looks much easier and clearer, just like this...

class Home extends StatelessWidget {
  final controller = Get.put(Controller());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("counter")),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Obx(() => Text(
                      'clicks: ${controller.count}',
                    )),
            ElevatedButton(
              child: Text('Next Route'),
              onPressed: () {
                Get.to(Second());
              },
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: controller.increment(),  
          ),
    );
  }
}
class Second extends StatelessWidget {
  final Controller ctrl = Get.find();
  @override
  Widget build(context){
     return Scaffold(body: Center(child: Text("${ctrl.count}")));
  }
}
Zealous Zebra

Ähnliche Antworten wie “Holen Sie sich in Dart”

Fragen ähnlich wie “Holen Sie sich in Dart”

Weitere verwandte Antworten zu “Holen Sie sich in Dart” auf Dart

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen