关于 Get 包,我不完全了解的一点是,是否总是需要将可观察变量放入控制器中。例如,这种情况有效:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() => runApp(App());
class App extends StatelessWidget {
final isTrue = true.obs;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Demo',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Scaffold(
body: Center(
child: Obx(
() => FlatButton(
color: isTrue.value ? Colors.blue : Colors.red,
child: Text('Hey'),
onPressed: () => isTrue.value = !isTrue.value,
),
),
),
),
);
}
}
但是是否会因此而出现泄漏/问题,并且在这种情况下是否需要 GetXController?