Created
March 8, 2022 12:13
-
-
Save huynguyennovem/015b9b0fd8ebe27c53f0f5efd9190bbf to your computer and use it in GitHub Desktop.
Scrollbar with ListView shows 2 scrollbars
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); | |
static const String _title = 'Flutter Code Sample'; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: _title, | |
home: Scaffold( | |
appBar: AppBar(title: const Text(_title)), | |
body: const Center( | |
child: MyStatefulWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyStatefulWidget extends StatefulWidget { | |
const MyStatefulWidget({Key? key}) : super(key: key); | |
@override | |
State<MyStatefulWidget> createState() => _MyStatefulWidgetState(); | |
} | |
class _MyStatefulWidgetState extends State<MyStatefulWidget> { | |
final ScrollController _firstController = ScrollController(); | |
@override | |
Widget build(BuildContext context) { | |
return LayoutBuilder( | |
builder: (BuildContext context, BoxConstraints constraints) { | |
return SizedBox( | |
width: constraints.maxWidth / 2, | |
// Only one scroll position can be attached to the | |
// PrimaryScrollController if using Scrollbars. Providing a | |
// unique scroll controller to this scroll view prevents it | |
// from attaching to the PrimaryScrollController. | |
child: Scrollbar( | |
isAlwaysShown: true, | |
controller: _firstController, | |
child: Padding( | |
padding: const EdgeInsets.all(48.0), | |
child: ListView.builder( | |
controller: _firstController, | |
itemCount: 100, | |
itemBuilder: (BuildContext context, int index) { | |
return Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Text('Scrollable 1 : Index $index'), | |
); | |
}), | |
), | |
),); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chrome 98.0.4758.109 (Official Build) (arm64)
Screen.Recording.2022-03-08.at.7.14.37.PM.mp4
Firstly I thought this issue come by he used same
ScrollController
for bothScrollbar
andListView
. So, I tried to use differentScrollController
for them, for eg:This leads to this issue: flutter/flutter#97873