Getx GetView
完美的搭配 Bindings:
class InjectSimplePage extends GetView<InjectSimpleController> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('MyPage')), body: Center( child: Obx(() => Text(controller.obj.toString())), ), floatingActionButton: FloatingActionButton( onPressed: () { controller.getAge(); }, child: Icon(Icons.add), ), ); } }
这里完全没有Get.find
,但是可以直接使用controller
,因为GetView
里封装好了:
abstract class GetView<T> extends StatelessWidget { const GetView({Key key}) : super(key: key); final String tag = null; T get controller => GetInstance().find<T>(tag: tag); @override Widget build(BuildContext context); }