Unverified Commit fc77aea3 authored by rami-a's avatar rami-a Committed by GitHub

Enable configuring minHeight for LinearProgressIndicator and update default to match spec (#55482)

parent cb88d2a3
...@@ -10,7 +10,6 @@ import 'package:flutter/widgets.dart'; ...@@ -10,7 +10,6 @@ import 'package:flutter/widgets.dart';
import 'material.dart'; import 'material.dart';
import 'theme.dart'; import 'theme.dart';
const double _kLinearProgressIndicatorHeight = 6.0;
const double _kMinCircularProgressIndicatorSize = 36.0; const double _kMinCircularProgressIndicatorSize = 36.0;
const int _kIndeterminateLinearDuration = 1800; const int _kIndeterminateLinearDuration = 1800;
...@@ -221,6 +220,9 @@ class _LinearProgressIndicatorPainter extends CustomPainter { ...@@ -221,6 +220,9 @@ class _LinearProgressIndicatorPainter extends CustomPainter {
/// The indicator line is displayed with [valueColor], an animated value. To /// The indicator line is displayed with [valueColor], an animated value. To
/// specify a constant color value use: `AlwaysStoppedAnimation<Color>(color)`. /// specify a constant color value use: `AlwaysStoppedAnimation<Color>(color)`.
/// ///
/// The minimum height of the indicator can be specified using [minHeight].
/// The indicator can be made taller by wrapping the widget with a [SizedBox].
///
/// See also: /// See also:
/// ///
/// * [CircularProgressIndicator], which shows progress along a circular arc. /// * [CircularProgressIndicator], which shows progress along a circular arc.
...@@ -236,9 +238,11 @@ class LinearProgressIndicator extends ProgressIndicator { ...@@ -236,9 +238,11 @@ class LinearProgressIndicator extends ProgressIndicator {
double value, double value,
Color backgroundColor, Color backgroundColor,
Animation<Color> valueColor, Animation<Color> valueColor,
this.minHeight,
String semanticsLabel, String semanticsLabel,
String semanticsValue, String semanticsValue,
}) : super( }) : assert(minHeight == null || minHeight > 0),
super(
key: key, key: key,
value: value, value: value,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
...@@ -247,6 +251,11 @@ class LinearProgressIndicator extends ProgressIndicator { ...@@ -247,6 +251,11 @@ class LinearProgressIndicator extends ProgressIndicator {
semanticsValue: semanticsValue, semanticsValue: semanticsValue,
); );
/// The minimum height of the line used to draw the indicator.
///
/// This defaults to 4dp.
final double minHeight;
@override @override
_LinearProgressIndicatorState createState() => _LinearProgressIndicatorState(); _LinearProgressIndicatorState createState() => _LinearProgressIndicatorState();
} }
...@@ -284,9 +293,9 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with ...@@ -284,9 +293,9 @@ class _LinearProgressIndicatorState extends State<LinearProgressIndicator> with
return widget._buildSemanticsWrapper( return widget._buildSemanticsWrapper(
context: context, context: context,
child: Container( child: Container(
constraints: const BoxConstraints( constraints: BoxConstraints(
minWidth: double.infinity, minWidth: double.infinity,
minHeight: _kLinearProgressIndicatorHeight, minHeight: widget.minHeight ?? 4.0,
), ),
child: CustomPaint( child: CustomPaint(
painter: _LinearProgressIndicatorPainter( painter: _LinearProgressIndicatorPainter(
......
...@@ -49,6 +49,27 @@ void main() { ...@@ -49,6 +49,27 @@ void main() {
handle.dispose(); handle.dispose();
}); });
testWidgets('LinearProgressIndicator custom minHeight', (WidgetTester tester) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: SizedBox(
width: 200.0,
child: LinearProgressIndicator(value: 0.25, minHeight: 2.0),
),
),
),
);
expect(
find.byType(LinearProgressIndicator),
paints
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 2.0))
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 2.0)),
);
});
testWidgets('LinearProgressIndicator paint (LTR)', (WidgetTester tester) async { testWidgets('LinearProgressIndicator paint (LTR)', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
...@@ -65,8 +86,8 @@ void main() { ...@@ -65,8 +86,8 @@ void main() {
expect( expect(
find.byType(LinearProgressIndicator), find.byType(LinearProgressIndicator),
paints paints
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 6.0)) ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0))
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 6.0)), ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 4.0)),
); );
expect(tester.binding.transientCallbackCount, 0); expect(tester.binding.transientCallbackCount, 0);
...@@ -88,8 +109,8 @@ void main() { ...@@ -88,8 +109,8 @@ void main() {
expect( expect(
find.byType(LinearProgressIndicator), find.byType(LinearProgressIndicator),
paints paints
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 6.0)) ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0))
..rect(rect: const Rect.fromLTRB(150.0, 0.0, 200.0, 6.0)), ..rect(rect: const Rect.fromLTRB(150.0, 0.0, 200.0, 4.0)),
); );
expect(tester.binding.transientCallbackCount, 0); expect(tester.binding.transientCallbackCount, 0);
...@@ -115,8 +136,8 @@ void main() { ...@@ -115,8 +136,8 @@ void main() {
expect( expect(
find.byType(LinearProgressIndicator), find.byType(LinearProgressIndicator),
paints paints
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 6.0)) ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0))
..rect(rect: Rect.fromLTRB(0.0, 0.0, animationValue * 200.0, 6.0)), ..rect(rect: Rect.fromLTRB(0.0, 0.0, animationValue * 200.0, 4.0)),
); );
expect(tester.binding.transientCallbackCount, 1); expect(tester.binding.transientCallbackCount, 1);
...@@ -142,8 +163,8 @@ void main() { ...@@ -142,8 +163,8 @@ void main() {
expect( expect(
find.byType(LinearProgressIndicator), find.byType(LinearProgressIndicator),
paints paints
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 6.0)) ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0))
..rect(rect: Rect.fromLTRB(200.0 - animationValue * 200.0, 0.0, 200.0, 6.0)), ..rect(rect: Rect.fromLTRB(200.0 - animationValue * 200.0, 0.0, 200.0, 4.0)),
); );
expect(tester.binding.transientCallbackCount, 1); expect(tester.binding.transientCallbackCount, 1);
...@@ -169,8 +190,8 @@ void main() { ...@@ -169,8 +190,8 @@ void main() {
expect( expect(
find.byType(LinearProgressIndicator), find.byType(LinearProgressIndicator),
paints paints
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 6.0)) ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 200.0, 4.0))
..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 6.0), color: Colors.white), ..rect(rect: const Rect.fromLTRB(0.0, 0.0, 50.0, 4.0), color: Colors.white),
); );
}); });
......
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