Skip to content

Instantly share code, notes, and snippets.

@chaudharydeepanshu
Created August 7, 2022 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaudharydeepanshu/7ba9a0d372913a792a0a7602d6fe255a to your computer and use it in GitHub Desktop.
Save chaudharydeepanshu/7ba9a0d372913a792a0a7602d6fe255a to your computer and use it in GitHub Desktop.
Task to bring down rebuilds of customContainer from 42 to 1
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