import 'package:flutter/material.dart'; import 'package:get/get.dart'; void main() { Get.lazyPut(() => Page2Controller(), fenix: true); runApp(GetMaterialApp(home: HomePage())); } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('HOME')), body: Center( child: RaisedButton( child: Text('Go to page 2'), onPressed: () => Get.to(() => Page2()), ), ), ); } } class Page2 extends StatelessWidget { final controller = Get.find(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Page2')), body: Center( child: Obx(() => Text(controller.number.toString())), ), floatingActionButton: FloatingActionButton( onPressed: () => controller.increment(), child: Icon(Icons.add), ), ); } } class Page2Controller extends GetxController { RxInt number = RxInt(0); increment() => number++; }