fix more than needed rebuilds on canvas children

this used a stupid builderFunc instead of a widget so flutter wasn't able to optimise those widget builds and it was simply a blanket rebuild. Added more examples as well
This commit is contained in:
2025-07-26 17:47:42 +00:00
parent 96e55a7157
commit 7ad54a92cb
8 changed files with 427 additions and 12 deletions
+53 -1
View File
@@ -1,4 +1,6 @@
import './app.dart';
import './caching_test.dart';
import './dynamic_widget_example.dart';
import 'package:flutter/material.dart';
void main() {
@@ -6,8 +8,58 @@ void main() {
MaterialApp(
// showPerformanceOverlay: true,
title: 'Infinite Lazy 2D Grid Example',
home: const App(),
home: const ExampleChooser(),
debugShowCheckedModeBanner: false,
),
);
}
class ExampleChooser extends StatelessWidget {
const ExampleChooser({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Infinite Lazy Grid Examples')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => const App()));
},
child: const Text('Original Example'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => const CachingTestApp()));
},
child: const Text('Widget Caching Test'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => const DynamicWidgetExample()));
},
child: const Text('Dynamic Widget Inputs'),
),
const SizedBox(height: 32),
const Padding(
padding: EdgeInsets.all(16.0),
child: Text(
'Examples:\n'
'• Original: Basic usage demo\n'
'• Caching Test: Shows Flutter\'s automatic widget optimization\n'
'• Dynamic Inputs: How to handle changing widget data',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 14, color: Colors.grey),
),
),
],
),
),
);
}
}