Commit 012d9381 authored by Hans Muller's avatar Hans Muller Committed by GitHub

RefreshIndicator backgroundColor (#4924)

parent a10cd03b
...@@ -31,15 +31,18 @@ class OverscrollDemoState extends State<OverscrollDemo> { ...@@ -31,15 +31,18 @@ class OverscrollDemoState extends State<OverscrollDemo> {
Completer<Null> completer = new Completer<Null>(); Completer<Null> completer = new Completer<Null>();
new Timer(new Duration(seconds: 3), () { completer.complete(null); }); new Timer(new Duration(seconds: 3), () { completer.complete(null); });
return completer.future.then((_) { return completer.future.then((_) {
_scaffoldKey.currentState.showSnackBar(new SnackBar( final ScaffoldState scaffoldState = _scaffoldKey.currentState;
content: new Text("Refresh complete"), if (scaffoldState != null) {
action: new SnackBarAction( scaffoldState.showSnackBar(new SnackBar(
label: 'RETRY', content: new Text("Refresh complete"),
onPressed: () { action: new SnackBarAction(
_refreshIndicatorKey.currentState.show(); label: 'RETRY',
} onPressed: () {
) _refreshIndicatorKey.currentState.show();
)); }
)
));
}
}); });
} }
......
...@@ -46,14 +46,15 @@ abstract class ProgressIndicator extends StatefulWidget { ...@@ -46,14 +46,15 @@ abstract class ProgressIndicator extends StatefulWidget {
/// much actual progress is being made. /// much actual progress is being made.
final double value; final double value;
/// The progress indicator's background color. If null, the background color is /// The progress indicator's background color. The current theme's
/// the current theme's backgroundColor. /// [ThemeData.backgroundColor] by default.
final Color backgroundColor; final Color backgroundColor;
/// The indicator's color is the animation's value. To specify a constant /// The indicator's color is the animation's value. To specify a constant
/// color use: `new AlwaysStoppedAnimation<Color>(color)`. /// color use: `new AlwaysStoppedAnimation<Color>(color)`.
/// ///
/// If null, the progress indicator is rendered with the current theme's primaryColor. /// If null, the progress indicator is rendered with the current theme's
/// [ThemeData.primaryColor].
final Animation<Color> valueColor; final Animation<Color> valueColor;
Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor; Color _getBackgroundColor(BuildContext context) => backgroundColor ?? Theme.of(context).backgroundColor;
...@@ -485,7 +486,7 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState { ...@@ -485,7 +486,7 @@ class _RefreshProgressIndicatorState extends _CircularProgressIndicatorState {
margin: const EdgeInsets.all(4.0), // acommodate the shadow margin: const EdgeInsets.all(4.0), // acommodate the shadow
child: new Material( child: new Material(
type: MaterialType.circle, type: MaterialType.circle,
color: Theme.of(context).canvasColor, color: config.backgroundColor ?? Theme.of(context).canvasColor,
elevation: 2, elevation: 2,
child: new Padding( child: new Padding(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
......
...@@ -68,18 +68,20 @@ enum _DismissTransition { ...@@ -68,18 +68,20 @@ enum _DismissTransition {
/// animated circular progress indicator is faded into view. When the scroll /// animated circular progress indicator is faded into view. When the scroll
/// ends, if the indicator has been dragged far enough for it to become /// ends, if the indicator has been dragged far enough for it to become
/// completely opaque, the refresh callback is called. The callback is /// completely opaque, the refresh callback is called. The callback is
/// expected to udpate the scrollback and then complete the Future it /// expected to update the scrollable's contents and then complete the Future
/// returns. The refresh indicator disappears after the callback's /// it returns. The refresh indicator disappears after the callback's
/// Future has completed. /// Future has completed.
/// ///
/// The required [scrollableKey] parameter identifies the scrollable widget /// The required [scrollableKey] parameter identifies the scrollable widget
/// whose scrollOffset is monitored by this RefreshIndicator. The same /// whose scrollOffset is monitored by this RefreshIndicator. The same
/// scrollableKey must also be set on the scrollable. See [Block.scrollableKey] /// scrollableKey must also be set on the scrollable. See [Block.scrollableKey],
/// [ScrollableList.scrollableKey], etc. /// [ScrollableList.scrollableKey], etc.
/// ///
/// See also: /// See also:
/// ///
/// * <https://www.google.com/design/spec/patterns/swipe-to-refresh.html> /// * <https://www.google.com/design/spec/patterns/swipe-to-refresh.html>
/// * [RefreshIndicatorState] (can be used to programatically show the refresh indicator)
/// * [RefreshProgressIndicator]
class RefreshIndicator extends StatefulWidget { class RefreshIndicator extends StatefulWidget {
/// Creates a refresh indicator. /// Creates a refresh indicator.
/// ///
...@@ -91,7 +93,9 @@ class RefreshIndicator extends StatefulWidget { ...@@ -91,7 +93,9 @@ class RefreshIndicator extends StatefulWidget {
this.child, this.child,
this.displacement: 40.0, this.displacement: 40.0,
this.refresh, this.refresh,
this.location: RefreshIndicatorLocation.top this.location: RefreshIndicatorLocation.top,
this.color,
this.backgroundColor
}) : super(key: key) { }) : super(key: key) {
assert(child != null); assert(child != null);
assert(refresh != null); assert(refresh != null);
...@@ -116,10 +120,18 @@ class RefreshIndicator extends StatefulWidget { ...@@ -116,10 +120,18 @@ class RefreshIndicator extends StatefulWidget {
/// Future must complete when the refresh operation is finished. /// Future must complete when the refresh operation is finished.
final RefreshCallback refresh; final RefreshCallback refresh;
/// Where the refresh indicator should appear, RefreshIndicatorLocation.top /// Where the refresh indicator should appear, [RefreshIndicatorLocation.top]
/// by default. /// by default.
final RefreshIndicatorLocation location; final RefreshIndicatorLocation location;
/// The progress indicator's foreground color. The current theme's
/// [ThemeData.primaryColor] by default.
final Color color;
/// The progress indicator's background color. The current theme's
/// [ThemeData.canvasColor] by default.
final Color backgroundColor;
@override @override
RefreshIndicatorState createState() => new RefreshIndicatorState(); RefreshIndicatorState createState() => new RefreshIndicatorState();
} }
...@@ -156,8 +168,8 @@ class RefreshIndicatorState extends State<RefreshIndicator> { ...@@ -156,8 +168,8 @@ class RefreshIndicatorState extends State<RefreshIndicator> {
// Fully opaque when we've reached config.displacement. // Fully opaque when we've reached config.displacement.
_valueColor = new ColorTween( _valueColor = new ColorTween(
begin: theme.primaryColor.withOpacity(0.0), begin: (config.color ?? theme.primaryColor).withOpacity(0.0),
end: theme.primaryColor.withOpacity(1.0) end: (config.color ?? theme.primaryColor).withOpacity(1.0)
) )
.animate(new CurvedAnimation( .animate(new CurvedAnimation(
parent: _sizeController, parent: _sizeController,
...@@ -369,7 +381,8 @@ class RefreshIndicatorState extends State<RefreshIndicator> { ...@@ -369,7 +381,8 @@ class RefreshIndicatorState extends State<RefreshIndicator> {
builder: (BuildContext context, Widget child) { builder: (BuildContext context, Widget child) {
return new RefreshProgressIndicator( return new RefreshProgressIndicator(
value: showIndeterminateIndicator ? null : _value.value, value: showIndeterminateIndicator ? null : _value.value,
valueColor: _valueColor valueColor: _valueColor,
backgroundColor: config.backgroundColor
); );
} }
) )
......
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