Created
July 15, 2019 23:59
-
-
Save Mike278/99cab86f3b908a06ae637b2d897b4a0c to your computer and use it in GitHub Desktop.
Listview jumps when scrolling from bottom to top
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'; | |
import 'package:rxdart/rxdart.dart'; | |
// Example: https://gfycat.com/clumsyslowamericanratsnake | |
void main() => runApp(MyApp()); | |
class MyBloc { | |
BehaviorSubject<String> _someData = BehaviorSubject(seedValue: "Hello"); | |
Stream<String> get someData => _someData.stream; | |
} | |
var bloc = MyBloc(); | |
class MyWidget extends StatelessWidget { | |
final String label; | |
const MyWidget({Key key, @required this.label}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return StreamBuilder<String>( | |
stream: bloc.someData, | |
builder: (context, snapshot) { | |
return snapshot.hasData | |
? Text("${snapshot.data} - $label") | |
: CircularProgressIndicator(); // Or some other tall-ish widget | |
} | |
); | |
} | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text("Test"), | |
), | |
body: Center( | |
child: ListView.builder( | |
itemCount: 50, | |
itemBuilder: (ctx, idx) { | |
return Padding( | |
padding: const EdgeInsets.all(12.0), | |
child: MyWidget(label: idx.toString()), | |
); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} |
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
name: streambuilder_list_bounce | |
description: A new Flutter project. | |
version: 1.0.0+1 | |
environment: | |
sdk: ">=2.1.0 <3.0.0" | |
dependencies: | |
flutter: | |
sdk: flutter | |
cupertino_icons: ^0.1.2 | |
rxdart: ^0.20.0 | |
dev_dependencies: | |
flutter_test: | |
sdk: flutter | |
flutter: | |
uses-material-design: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment