Commit cc72a8e5 authored by Hans Muller's avatar Hans Muller

Merge pull request #2884 from HansMuller/scrollbar_thumb

Scrollbar thumb color, etc
parents 51b6f0ea d89ccc4a
...@@ -9,9 +9,7 @@ class TwoLevelListDemo extends StatelessWidget { ...@@ -9,9 +9,7 @@ class TwoLevelListDemo extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
appBar: new AppBar(title: new Text('Expand/Collapse List Control')), appBar: new AppBar(title: new Text('Expand/Collapse List Control')),
body: new Padding( body: new TwoLevelList(
padding: const EdgeInsets.all(0.0),
child: new TwoLevelList(
type: MaterialListType.oneLine, type: MaterialListType.oneLine,
items: <Widget>[ items: <Widget>[
new TwoLevelListItem(title: new Text('Top')), new TwoLevelListItem(title: new Text('Top')),
...@@ -27,7 +25,6 @@ class TwoLevelListDemo extends StatelessWidget { ...@@ -27,7 +25,6 @@ class TwoLevelListDemo extends StatelessWidget {
new TwoLevelListItem(title: new Text('Bottom')) new TwoLevelListItem(title: new Text('Bottom'))
] ]
) )
)
); );
} }
} }
...@@ -54,7 +54,7 @@ class _GestureArena { ...@@ -54,7 +54,7 @@ class _GestureArena {
/// If a gesture attempts to win while the arena is still open, it becomes the /// If a gesture attempts to win while the arena is still open, it becomes the
/// "eager winnner". We look for an eager winner when closing the arena to new /// "eager winnner". We look for an eager winner when closing the arena to new
/// participants, and if there is one, we resolve the arena it its favour at /// participants, and if there is one, we resolve the arena in its favor at
/// that time. /// that time.
GestureArenaMember eagerWinner; GestureArenaMember eagerWinner;
......
...@@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart'; ...@@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
import 'constants.dart'; import 'constants.dart';
import 'scrollbar_painter.dart'; import 'scrollbar_painter.dart';
import 'theme.dart';
enum MaterialListType { enum MaterialListType {
oneLine, oneLine,
...@@ -44,7 +45,15 @@ class MaterialList extends StatefulWidget { ...@@ -44,7 +45,15 @@ class MaterialList extends StatefulWidget {
} }
class _MaterialListState extends State<MaterialList> { class _MaterialListState extends State<MaterialList> {
ScrollbarPainter _scrollbarPainter = new ScrollbarPainter(); ScrollbarPainter _scrollbarPainter;
@override
void initState() {
super.initState();
_scrollbarPainter = new ScrollbarPainter(
getThumbColor: () => Theme.of(context).highlightColor
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
......
...@@ -10,16 +10,20 @@ const double _kMinScrollbarThumbLength = 18.0; ...@@ -10,16 +10,20 @@ const double _kMinScrollbarThumbLength = 18.0;
const double _kScrollbarThumbGirth = 6.0; const double _kScrollbarThumbGirth = 6.0;
const Duration _kScrollbarThumbFadeDuration = const Duration(milliseconds: 300); const Duration _kScrollbarThumbFadeDuration = const Duration(milliseconds: 300);
typedef Color GetThumbColor();
class ScrollbarPainter extends ScrollableListPainter { class ScrollbarPainter extends ScrollableListPainter {
ScrollbarPainter({ GetThumbColor getThumbColor }) {
this.getThumbColor = getThumbColor ?? _defaultThumbColor;
}
GetThumbColor getThumbColor;
double _opacity = 0.0; double _opacity = 0.0;
int get _alpha => (_opacity * 0xFF).round();
// TODO(hansmuller): thumb color should come from ThemeData. Color _defaultThumbColor() => const Color(0xFF9E9E9E);
Color get thumbColor => const Color(0xFF9E9E9E);
void paintThumb(PaintingContext context, Rect thumbBounds) { void paintThumb(PaintingContext context, Rect thumbBounds) {
final Paint paint = new Paint()..color = thumbColor.withAlpha(_alpha); final Paint paint = new Paint()..color = getThumbColor().withOpacity(_opacity);
context.canvas.drawRect(thumbBounds, paint); context.canvas.drawRect(thumbBounds, paint);
} }
...@@ -54,7 +58,7 @@ class ScrollbarPainter extends ScrollableListPainter { ...@@ -54,7 +58,7 @@ class ScrollbarPainter extends ScrollableListPainter {
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (_alpha == 0) if (_opacity == 0.0)
return; return;
paintScrollbar(context, offset); paintScrollbar(context, offset);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment