diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 718eb29622..01baee7e00 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -118,8 +118,7 @@ class _DatePickerState extends State { ); break; } - return new Column( - crossAxisAlignment: CrossAxisAlignment.stretch, + return new BlockBody( children: [ header, new Container( @@ -213,7 +212,6 @@ const double _kMaxDayPickerHeight = _kDayPickerRowHeight * (_kMaxDayPickerRowCou class _DayPickerGridDelegate extends GridDelegateWithInOrderChildPlacement { @override GridSpecification getGridSpecification(BoxConstraints constraints, int childCount) { - assert(constraints.maxWidth < double.INFINITY); final int columnCount = DateTime.DAYS_PER_WEEK; return new GridSpecification.fromRegularTiles( tileWidth: constraints.maxWidth / columnCount, @@ -459,34 +457,37 @@ class _MonthPickerState extends State { @override Widget build(BuildContext context) { - return new Stack( - children: [ - new PageableLazyList( - key: _dayPickerListKey, - initialScrollOffset: _monthDelta(config.firstDate, config.selectedDate).toDouble(), - scrollDirection: Axis.horizontal, - itemCount: _monthDelta(config.firstDate, config.lastDate) + 1, - itemBuilder: _buildItems - ), - new Positioned( - top: 0.0, - left: 8.0, - child: new IconButton( - icon: new Icon(Icons.chevron_left), - tooltip: 'Previous month', - onPressed: _handlePreviousMonth + return new SizedBox( + width: 330.0, + child: new Stack( + children: [ + new PageableLazyList( + key: _dayPickerListKey, + initialScrollOffset: _monthDelta(config.firstDate, config.selectedDate).toDouble(), + scrollDirection: Axis.horizontal, + itemCount: _monthDelta(config.firstDate, config.lastDate) + 1, + itemBuilder: _buildItems + ), + new Positioned( + top: 0.0, + left: 8.0, + child: new IconButton( + icon: new Icon(Icons.chevron_left), + tooltip: 'Previous month', + onPressed: _handlePreviousMonth + ) + ), + new Positioned( + top: 0.0, + right: 8.0, + child: new IconButton( + icon: new Icon(Icons.chevron_right), + tooltip: 'Next month', + onPressed: _handleNextMonth + ) ) - ), - new Positioned( - top: 0.0, - right: 8.0, - child: new IconButton( - icon: new Icon(Icons.chevron_right), - tooltip: 'Next month', - onPressed: _handleNextMonth - ) - ) - ] + ] + ) ); } diff --git a/packages/flutter/lib/src/material/time_picker.dart b/packages/flutter/lib/src/material/time_picker.dart index 3face3e1ec..04f13f66c1 100644 --- a/packages/flutter/lib/src/material/time_picker.dart +++ b/packages/flutter/lib/src/material/time_picker.dart @@ -33,7 +33,7 @@ class TimeOfDay { /// /// The [hour] argument must be between 0 and 23, inclusive. The [minute] /// argument must be between 0 and 59, inclusive. - const TimeOfDay({ this.hour, this.minute }); + const TimeOfDay({ @required this.hour, @required this.minute }); /// Returns a new TimeOfDay with the hour and/or minute replaced. TimeOfDay replacing({ int hour, int minute }) { @@ -42,7 +42,7 @@ class TimeOfDay { return new TimeOfDay(hour: hour ?? this.hour, minute: minute ?? this.minute); } - /// The selected hour, in 24 hour time from 0..23 + /// The selected hour, in 24 hour time from 0..23. final int hour; /// The selected minute. diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index 84702a8755..4a0527cc3d 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -197,6 +197,8 @@ class RenderConstrainedBox extends RenderProxyBox { @override double computeMinIntrinsicWidth(double height) { + if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth) + return _additionalConstraints.minWidth; final double width = super.computeMinIntrinsicWidth(height); if (_additionalConstraints.hasBoundedWidth) return _additionalConstraints.constrainWidth(width); @@ -205,6 +207,8 @@ class RenderConstrainedBox extends RenderProxyBox { @override double computeMaxIntrinsicWidth(double height) { + if (_additionalConstraints.hasBoundedWidth && _additionalConstraints.hasTightWidth) + return _additionalConstraints.minWidth; final double width = super.computeMaxIntrinsicWidth(height); if (_additionalConstraints.hasBoundedWidth) return _additionalConstraints.constrainWidth(width); @@ -213,6 +217,8 @@ class RenderConstrainedBox extends RenderProxyBox { @override double computeMinIntrinsicHeight(double width) { + if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight) + return _additionalConstraints.minHeight; final double height = super.computeMinIntrinsicHeight(width); if (_additionalConstraints.hasBoundedHeight) return _additionalConstraints.constrainHeight(height); @@ -221,6 +227,8 @@ class RenderConstrainedBox extends RenderProxyBox { @override double computeMaxIntrinsicHeight(double width) { + if (_additionalConstraints.hasBoundedHeight && _additionalConstraints.hasTightHeight) + return _additionalConstraints.minHeight; final double height = super.computeMaxIntrinsicHeight(width); if (_additionalConstraints.hasBoundedHeight) return _additionalConstraints.constrainHeight(height); diff --git a/packages/flutter/lib/src/rendering/viewport.dart b/packages/flutter/lib/src/rendering/viewport.dart index e7238727f5..31c48c9ffe 100644 --- a/packages/flutter/lib/src/rendering/viewport.dart +++ b/packages/flutter/lib/src/rendering/viewport.dart @@ -400,7 +400,7 @@ abstract class RenderVirtualViewport[ + new OverlayEntry( + builder: (BuildContext context) => new StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return new Positioned( + width: 400.0, + child: new Block( + children: [ + new Material( + child: new DatePicker( + firstDate: new DateTime(0), + lastDate: new DateTime(9999), + key: _datePickerKey, + selectedDate: _selectedDate, + onChanged: (DateTime value) { + setState(() { + _selectedDate = value; + }); + } + ) + ) + ] + ) + ); + } + ) + ) + ] + ) + ); + + await tester.tapAt(const Point(50.0, 200.0)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.JULY, 26))); + await tester.pump(const Duration(seconds: 2)); + + await tester.tapAt(const Point(300.0, 200.0)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.JULY, 1))); + await tester.pump(const Duration(seconds: 2)); + + await tester.tapAt(const Point(380.0, 120.0)); + await tester.pump(); + await tester.pump(const Duration(seconds: 2)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.JULY, 1))); + + await tester.tapAt(const Point(300.0, 200.0)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.AUGUST, 5))); + await tester.pump(const Duration(seconds: 2)); + + await tester.scroll(find.byKey(_datePickerKey), const Offset(-300.0, 0.0)); + await tester.pump(); + await tester.pump(const Duration(seconds: 2)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.AUGUST, 5))); + + await tester.tapAt(const Point(45.0, 370.0)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.SEPTEMBER, 25))); + await tester.pump(const Duration(seconds: 2)); + + await tester.scroll(find.byKey(_datePickerKey), const Offset(300.0, 10.0)); + await tester.pump(); + await tester.pump(const Duration(seconds: 2)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.SEPTEMBER, 25))); + + await tester.tapAt(const Point(210.0, 280.0)); + expect(_selectedDate, equals(new DateTime(2016, DateTime.AUGUST, 17))); + await tester.pump(const Duration(seconds: 2)); + + }); + + testWidgets('render picker with intrinsic dimensions', (WidgetTester tester) async { + await tester.pumpWidget( + new Overlay( + initialEntries: [ + new OverlayEntry( + builder: (BuildContext context) => new StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return new IntrinsicWidth( + child: new IntrinsicHeight( + child: new Material( + child: new Block( + children: [ + new DatePicker( + firstDate: new DateTime(0), + lastDate: new DateTime(9999), + onChanged: null, + selectedDate: new DateTime(2000, DateTime.JANUARY, 1) + ) + ] + ) + ) + ) + ); + } + ) + ) + ] + ) + ); + await tester.pump(const Duration(seconds: 5)); + }); + +} diff --git a/packages/flutter/test/material/time_picker_test.dart b/packages/flutter/test/material/time_picker_test.dart index 6488566e4a..9d760a630b 100644 --- a/packages/flutter/test/material/time_picker_test.dart +++ b/packages/flutter/test/material/time_picker_test.dart @@ -15,7 +15,7 @@ void main() { builder: (BuildContext context, StateSetter setState) { return new Material( child: new Center( - child: new SizedBox( + child: new SizedBox( width: 200.0, height: 400.0, child: new TimePicker( @@ -56,6 +56,20 @@ void main() { await tester.pump(const Duration(seconds: 1)); // Finish settling animation. }); + testWidgets('render picker with intrinsic dimensions', (WidgetTester tester) async { + await tester.pumpWidget( + new IntrinsicWidth( + child: new IntrinsicHeight( + child: new TimePicker( + onChanged: null, + selectedTime: new TimeOfDay(hour: 0, minute: 0) + ) + ) + ) + ); + await tester.pump(const Duration(seconds: 5)); + }); + testWidgets('drag-select an hour', (WidgetTester tester) async { Key _timePickerKey = new UniqueKey(); TimeOfDay _selectedTime = const TimeOfDay(hour: 7, minute: 0);