Warning: Prefer const with constant constructors
cause: - Text("dd")
solution: - const Text("dd")
StatefulWidget instances themselves are immutable and store their
mutable state either in separate State objects that are created by the createState
method, or in objects to which that State subscribes, for example Stream or
ChangeNotifier objects, to which references are stored in final fields on the
StatefulWidget itself.
Sources:
https://api.flutter.dev/flutter/widgets/StatefulWidget-class.html
https://stackoverflow.com/a/58136993/462608
Please give examples to show how do widgets store their mutable states by createState
method or in objects to which that State subscribes.
Example:
Which field here is considered mutable
?
class CategoryScreen extends StatefulWidget {
String productId;
CategoryScreen(this.productId);
@override
CategoryScreenState createState() => CategoryScreenState();
}
class CategoryScreenState extends State<CategoryScreen> {
List<Item> _data = [];
CategoryController controller = Get.put(CategoryController());
setState(() {
controller.selectedCategoryIndex.value = panelIndex;
});
}