mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Scrollbar thumb color, etc
This commit is contained in:
parent
51b6f0eae7
commit
d89ccc4aad
@ -9,24 +9,21 @@ class TwoLevelListDemo extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
appBar: new AppBar(title: new Text('Expand/Collapse List Control')),
|
||||
body: new Padding(
|
||||
padding: const EdgeInsets.all(0.0),
|
||||
child: new TwoLevelList(
|
||||
type: MaterialListType.oneLine,
|
||||
items: <Widget>[
|
||||
new TwoLevelListItem(title: new Text('Top')),
|
||||
new TwoLevelSublist(
|
||||
title: new Text('Sublist'),
|
||||
children: <Widget>[
|
||||
new TwoLevelListItem(title: new Text('One')),
|
||||
new TwoLevelListItem(title: new Text('Two')),
|
||||
new TwoLevelListItem(title: new Text('Free')),
|
||||
new TwoLevelListItem(title: new Text('Four'))
|
||||
]
|
||||
),
|
||||
new TwoLevelListItem(title: new Text('Bottom'))
|
||||
]
|
||||
)
|
||||
body: new TwoLevelList(
|
||||
type: MaterialListType.oneLine,
|
||||
items: <Widget>[
|
||||
new TwoLevelListItem(title: new Text('Top')),
|
||||
new TwoLevelSublist(
|
||||
title: new Text('Sublist'),
|
||||
children: <Widget>[
|
||||
new TwoLevelListItem(title: new Text('One')),
|
||||
new TwoLevelListItem(title: new Text('Two')),
|
||||
new TwoLevelListItem(title: new Text('Free')),
|
||||
new TwoLevelListItem(title: new Text('Four'))
|
||||
]
|
||||
),
|
||||
new TwoLevelListItem(title: new Text('Bottom'))
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class _GestureArena {
|
||||
|
||||
/// 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
|
||||
/// 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.
|
||||
GestureArenaMember eagerWinner;
|
||||
|
||||
|
@ -6,6 +6,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'constants.dart';
|
||||
import 'scrollbar_painter.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
enum MaterialListType {
|
||||
oneLine,
|
||||
@ -44,7 +45,15 @@ class MaterialList extends StatefulWidget {
|
||||
}
|
||||
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -10,16 +10,20 @@ const double _kMinScrollbarThumbLength = 18.0;
|
||||
const double _kScrollbarThumbGirth = 6.0;
|
||||
const Duration _kScrollbarThumbFadeDuration = const Duration(milliseconds: 300);
|
||||
|
||||
typedef Color GetThumbColor();
|
||||
|
||||
class ScrollbarPainter extends ScrollableListPainter {
|
||||
ScrollbarPainter({ GetThumbColor getThumbColor }) {
|
||||
this.getThumbColor = getThumbColor ?? _defaultThumbColor;
|
||||
}
|
||||
|
||||
GetThumbColor getThumbColor;
|
||||
double _opacity = 0.0;
|
||||
int get _alpha => (_opacity * 0xFF).round();
|
||||
|
||||
// TODO(hansmuller): thumb color should come from ThemeData.
|
||||
Color get thumbColor => const Color(0xFF9E9E9E);
|
||||
Color _defaultThumbColor() => const Color(0xFF9E9E9E);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -54,7 +58,7 @@ class ScrollbarPainter extends ScrollableListPainter {
|
||||
|
||||
@override
|
||||
void paint(PaintingContext context, Offset offset) {
|
||||
if (_alpha == 0)
|
||||
if (_opacity == 0.0)
|
||||
return;
|
||||
paintScrollbar(context, offset);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user