Skip to content

Instantly share code, notes, and snippets.

@vaibhav93
Created December 30, 2018 07:49
Show Gist options
  • Save vaibhav93/d62f3e8cb715f8b0ee0c1cb4f6329a45 to your computer and use it in GitHub Desktop.
Save vaibhav93/d62f3e8cb715f8b0ee0c1cb4f6329a45 to your computer and use it in GitHub Desktop.
Flutter CustomScrollView Bug
import 'dart:async';
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',
home: Scaffold(
appBar: AppBar(title: Text("App"),),
body: MyHomePage(),
)
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final streamController = StreamController();
final String title;
@override
Widget build(BuildContext context) {
// Add some data
streamController.sink.add(1);
return CustomScrollView(
slivers: <Widget>[
// If we comment this SliverBoxAdapter, error "'center.parent == this': is not true" shows up
// Error disappears on hot reload. To see error, comment SliverBoxAdapter, stop app and start.
// SliverToBoxAdapter(child: Center(child: Icon(Icons.error),),),
StreamBuilder(
stream: streamController.stream,
builder: (context,snapshot){
if(snapshot.hasData) {
return SliverList(
delegate: SliverChildListDelegate(<Widget>[Text("hi")]),
);
}
return SliverFillRemaining(child: Center(child: Icon(Icons.error),),);
},
)
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment