Created
January 11, 2019 22:38
-
-
Save MariaMelnik/3c95215032689bcdbc781289483d594f to your computer and use it in GitHub Desktop.
Flutter: slivers+StreamBuilder
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(MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
Stream<int> stream; | |
@override | |
void initState() { | |
stream = Stream.periodic(Duration(seconds: 1), (int i) => i); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: CustomScrollView(slivers: <Widget>[ | |
SliverAppBar( | |
title: Text('Sliver App Bar'), | |
floating: true, | |
snap: true, | |
bottom: PreferredSize( | |
preferredSize: const Size.fromHeight(90.0), | |
child: Text('dddd'), | |
), | |
), | |
StreamBuilder( | |
stream: stream, | |
builder: (context, snapshot) => SliverList( | |
delegate: SliverChildBuilderDelegate( | |
(context, index) => ListTile(title: Text(snapshot.data.toString())), | |
childCount: snapshot.hasData ? 1 : 0, | |
) | |
) | |
) | |
]) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you so much for this!!!