Skip to content

Instantly share code, notes, and snippets.

@MariaMelnik
Created January 11, 2019 22:38
Show Gist options
  • Select an option

  • Save MariaMelnik/3c95215032689bcdbc781289483d594f to your computer and use it in GitHub Desktop.

Select an option

Save MariaMelnik/3c95215032689bcdbc781289483d594f to your computer and use it in GitHub Desktop.
Flutter: slivers+StreamBuilder
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,
)
)
)
])
);
}
}
Copy link

ghost commented Oct 4, 2022

thank you so much for this!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment