Created with <3 with dartpad.dev.
Last active
August 25, 2022 16:42
-
-
Save petermnt/9f690f3e7131729b39e8dbb72a991213 to your computer and use it in GitHub Desktop.
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); | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Slivers', | |
theme: ThemeData.light(), | |
darkTheme: ThemeData.dark(), | |
themeMode: ThemeMode.system, | |
home: const Page(), | |
); | |
} | |
} | |
class Page extends StatelessWidget { | |
const Page({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: CustomScrollView( | |
slivers: <Widget>[ | |
SliverList( | |
delegate: SliverChildBuilderDelegate( | |
(context, index) => BuildNotifyingWidget( | |
"Sliver list builder", | |
child: Text("Sliver list builder $index"), | |
), | |
childCount: 50, | |
), | |
), | |
SliverList( | |
delegate: SliverChildBuilderDelegate( | |
(context, index) => BuildNotifyingWidget( | |
"Sliver list builder 2", | |
child: Text("Sliver list builder 2 $index"), | |
), | |
childCount: 50, | |
), | |
), | |
SliverList( | |
delegate: SliverChildListDelegate( | |
List.generate( | |
50, | |
(index) => BuildNotifyingWidget( | |
"Sliver list", | |
child: Text("Sliver list $index"), | |
), | |
).toList(), | |
), | |
), | |
SliverToBoxAdapter( | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: List.generate( | |
50, | |
(index) => BuildNotifyingWidget( | |
"SliverToBoxAdapter", | |
child: Text("SliverToBoxAdapter $index"), | |
), | |
), | |
), | |
) | |
], | |
), | |
); | |
} | |
} | |
class BuildNotifyingWidget extends StatelessWidget { | |
final String prefix; | |
final Widget child; | |
BuildNotifyingWidget(this.prefix, {required this.child, Key? key}) | |
: super(key: key) { | |
print("creating object from $prefix ($child)"); | |
} | |
@override | |
Widget build(BuildContext context) { | |
print("building from $prefix ($child)"); | |
return Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: SizedBox( | |
height: 50, | |
child: child, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment