From 0d454724d3707f0ed1c813cddc74a57dd1ed7173 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 6 Sep 2017 15:35:19 -0700 Subject: [PATCH] Improve DatePicker RTL (#11922) This patch just fixes the next and previous buttons to be in the proper place. There might be other issues with the DatePicker, but this one was obvious. See #11377 --- .../flutter/lib/src/material/date_picker.dart | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/packages/flutter/lib/src/material/date_picker.dart b/packages/flutter/lib/src/material/date_picker.dart index 8e14f8ebd9..2a8a7ec7e2 100644 --- a/packages/flutter/lib/src/material/date_picker.dart +++ b/packages/flutter/lib/src/material/date_picker.dart @@ -10,7 +10,7 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; import 'package:intl/date_symbols.dart'; -import 'package:intl/intl.dart'; +import 'package:intl/intl.dart' hide TextDirection; import 'button.dart'; import 'button_bar.dart'; @@ -533,8 +533,31 @@ class _MonthPickerState extends State { }); } + Icon _getPreviousMonthIcon(TextDirection textDirection) { + assert(textDirection != null); + switch (textDirection) { + case TextDirection.rtl: + return const Icon(Icons.chevron_right); + case TextDirection.ltr: + return const Icon(Icons.chevron_left); + } + return null; + } + + Icon _getNextMonthIcon(TextDirection textDirection) { + assert(textDirection != null); + switch (textDirection) { + case TextDirection.rtl: + return const Icon(Icons.chevron_left); + case TextDirection.ltr: + return const Icon(Icons.chevron_right); + } + return null; + } + @override Widget build(BuildContext context) { + final TextDirection textDirection = Directionality.of(context); return new SizedBox( width: _kMonthPickerPortraitWidth, height: _kMaxDayPickerHeight, @@ -548,20 +571,20 @@ class _MonthPickerState extends State { itemBuilder: _buildItems, onPageChanged: _handleMonthPageChanged, ), - new Positioned( + new PositionedDirectional( top: 0.0, - left: 8.0, + start: 8.0, child: new IconButton( - icon: const Icon(Icons.chevron_left), + icon: _getPreviousMonthIcon(textDirection), tooltip: MaterialLocalizations.of(context).previousMonthTooltip, onPressed: _isDisplayingFirstMonth ? null : _handlePreviousMonth, ), ), - new Positioned( + new PositionedDirectional( top: 0.0, - right: 8.0, + end: 8.0, child: new IconButton( - icon: const Icon(Icons.chevron_right), + icon: _getNextMonthIcon(textDirection), tooltip: MaterialLocalizations.of(context).nextMonthTooltip, onPressed: _isDisplayingLastMonth ? null : _handleNextMonth, ),