Search
 
SCRIPT & CODE EXAMPLE
 

DART

get 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}")));
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: create a int list dart 
Dart :: how to check system environment variables in dart 
Dart :: flutter scrollable columne 
Dart :: convert future list to list dart 
Dart :: dart enums 
Dart :: flutter disable focusable 
Dart :: get single element from list in dart 
Dart :: dart list 
Dart :: heart shape container flutter 
Dart :: flutter nimations 
Dart :: dart remove from list 
Dart :: add all items to a list in dart 
Dart :: flutter button playing sound 
Dart :: anonymous function in dart 
Dart :: dart set final variable in constructor 
Dart :: dart set.generate 
Dart :: onpressed null flutter 
Dart :: Flutter find if offset inside a polygon 
Dart :: display numbered text in flutter 
Dart :: var dump print object flutter dart 
Dart :: desing patters para Flutter 
Dart :: glowing buttons in flutter 
Dart :: what is the problem to aqueduct with dart 2.8 
Swift :: save date to userdefaults swift 
Swift :: convert string to int swift 
Swift :: remove divider list swiftui 
Swift :: ShareSheet: UIViewControllerRepresentable swiftui 
Swift :: save Codable in userdefaults and fetch codable from userdefaults ios swift 
Swift :: swift ways to setup constraints 
Swift :: swift webview load html 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =