Created
October 2, 2021 22:00
-
-
Save iapicca/d1caeec41b94adf4ceee819862f4c2de to your computer and use it in GitHub Desktop.
issue 91157
This file contains hidden or 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 WidgetThatPrintWhenIsBuilt extends StatelessWidget { | |
| final String text; | |
| WidgetThatPrintWhenIsBuilt({ | |
| required this.text, | |
| }) : super(key: ValueKey('WidgetThatPrintWhenIsBuilt:$text')); | |
| @override | |
| Widget build(BuildContext context) { | |
| print('building "$text"'); | |
| return Text( | |
| text, | |
| key: ValueKey(text), | |
| style: const TextStyle(fontSize: 40), | |
| ); | |
| } | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({ | |
| final key = const ValueKey('MyApp'), | |
| }) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return const MaterialApp(home: MyHomePage()); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| const MyHomePage({ | |
| final key = const ValueKey('MyHomePage'), | |
| }) : super(key: key); | |
| @override | |
| State<MyHomePage> createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> { | |
| late final ScrollController _controller; | |
| final _list = [for (var i = 0; i < 40; ++i) i]; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| _controller = ScrollController(); | |
| } | |
| @override | |
| void dispose() { | |
| super.dispose(); | |
| _controller.dispose(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| key: const ValueKey('Scaffold'), | |
| body: CustomScrollView( | |
| key: const ValueKey('CustomScrollView'), | |
| controller: _controller, | |
| slivers: [ | |
| SliverList( | |
| key: const ValueKey('SliverList'), | |
| delegate: SliverChildBuilderDelegate( | |
| (context, index) => | |
| WidgetThatPrintWhenIsBuilt(text: '${_list[index]}'), | |
| childCount: _list.length, | |
| ), | |
| ) | |
| ], | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: () => setState(() => _list.add(_list.length)), | |
| tooltip: 'Increment', | |
| child: const Icon(Icons.add), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment