Created
August 7, 2022 12:45
-
-
Save chaudharydeepanshu/7ba9a0d372913a792a0a7602d6fe255a to your computer and use it in GitHub Desktop.
Task to bring down rebuilds of customContainer from 42 to 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.light(), | |
darkTheme: ThemeData.dark(), | |
themeMode: ThemeMode.system, | |
home: const Home(), | |
); | |
} | |
} | |
class Home extends StatelessWidget { | |
const Home({Key? key}) : super(key: key); | |
final Widget customContainer = const CustomContainer(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text("Grid"), | |
), | |
body: GridView( | |
shrinkWrap: true, | |
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( | |
childAspectRatio: 1, | |
crossAxisCount: 7, | |
mainAxisExtent: 40, | |
crossAxisSpacing: 5, | |
mainAxisSpacing: 5, | |
), | |
children: List.generate(42, (index) { | |
return customContainer; | |
}), | |
), | |
); | |
} | |
} | |
class CustomContainer extends StatelessWidget { | |
const CustomContainer({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.pink, | |
height: 40, | |
width: 40, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment