Assign late variable without initstate in flutter_gallery (#83020)

This commit is contained in:
Abhishek Ghaskata 2021-05-25 07:29:03 +05:30 committed by GitHub
parent a8ec764609
commit e989d6b1fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 17 deletions

View file

@ -302,21 +302,15 @@ class Tab1ItemPage extends StatefulWidget {
}
class Tab1ItemPageState extends State<Tab1ItemPage> {
@override
void initState() {
super.initState();
relatedColors = List<Color>.generate(10, (int index) {
final math.Random random = math.Random(widget.randomSeed);
return Color.fromARGB(
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;
late final List<Color> relatedColors = List<Color>.generate(10, (int index) {
final math.Random random = math.Random(widget.randomSeed);
return Color.fromARGB(
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),
);
});
@override
Widget build(BuildContext context) {

View file

@ -45,7 +45,7 @@ class GalleryApp extends StatefulWidget {
class _GalleryAppState extends State<GalleryApp> {
GalleryOptions? _options;
Timer? _timeDilationTimer;
late AppStateModel model;
late final AppStateModel model = AppStateModel()..loadProducts();
Map<String, WidgetBuilder> _buildRoutes() {
// For a different example of how to set up an application routing table
@ -66,7 +66,6 @@ class _GalleryAppState extends State<GalleryApp> {
timeDilation: timeDilation,
platform: defaultTargetPlatform,
);
model = AppStateModel()..loadProducts();
}
@override