Unverified Commit e989d6b1 authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

Assign late variable without initstate in flutter_gallery (#83020)

parent a8ec7646
...@@ -302,21 +302,15 @@ class Tab1ItemPage extends StatefulWidget { ...@@ -302,21 +302,15 @@ class Tab1ItemPage extends StatefulWidget {
} }
class Tab1ItemPageState extends State<Tab1ItemPage> { class Tab1ItemPageState extends State<Tab1ItemPage> {
@override late final List<Color> relatedColors = List<Color>.generate(10, (int index) {
void initState() { final math.Random random = math.Random(widget.randomSeed);
super.initState(); return Color.fromARGB(
relatedColors = List<Color>.generate(10, (int index) { 255,
final math.Random random = math.Random(widget.randomSeed); (widget.color!.red + random.nextInt(100) - 50).clamp(0, 255),
return Color.fromARGB( (widget.color!.green + random.nextInt(100) - 50).clamp(0, 255),
255, (widget.color!.blue + random.nextInt(100) - 50).clamp(0, 255),
(widget.color!.red + random.nextInt(100) - 50).clamp(0, 255), );
(widget.color!.green + random.nextInt(100) - 50).clamp(0, 255), });
(widget.color!.blue + random.nextInt(100) - 50).clamp(0, 255),
);
});
}
late List<Color> relatedColors;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -45,7 +45,7 @@ class GalleryApp extends StatefulWidget { ...@@ -45,7 +45,7 @@ class GalleryApp extends StatefulWidget {
class _GalleryAppState extends State<GalleryApp> { class _GalleryAppState extends State<GalleryApp> {
GalleryOptions? _options; GalleryOptions? _options;
Timer? _timeDilationTimer; Timer? _timeDilationTimer;
late AppStateModel model; late final AppStateModel model = AppStateModel()..loadProducts();
Map<String, WidgetBuilder> _buildRoutes() { Map<String, WidgetBuilder> _buildRoutes() {
// For a different example of how to set up an application routing table // For a different example of how to set up an application routing table
...@@ -66,7 +66,6 @@ class _GalleryAppState extends State<GalleryApp> { ...@@ -66,7 +66,6 @@ class _GalleryAppState extends State<GalleryApp> {
timeDilation: timeDilation, timeDilation: timeDilation,
platform: defaultTargetPlatform, platform: defaultTargetPlatform,
); );
model = AppStateModel()..loadProducts();
} }
@override @override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment