mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Use OverflowBar instead of ButtonBar in DatePicker (#62686)
This commit is contained in:
parent
17d317977b
commit
ddeb5bb9c8
|
@ -9,8 +9,6 @@ import 'dart:math' as math;
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../button_bar.dart';
|
||||
import '../button_theme.dart';
|
||||
import '../color_scheme.dart';
|
||||
import '../debug.dart';
|
||||
import '../dialog.dart';
|
||||
|
@ -383,19 +381,23 @@ class _DatePickerDialogState extends State<_DatePickerDialog> {
|
|||
? textTheme.headline5?.copyWith(color: dateColor)
|
||||
: textTheme.headline4?.copyWith(color: dateColor);
|
||||
|
||||
final Widget actions = ButtonBar(
|
||||
buttonTextTheme: ButtonTextTheme.primary,
|
||||
layoutBehavior: ButtonBarLayoutBehavior.constrained,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: Text(widget.cancelText ?? localizations.cancelButtonLabel),
|
||||
onPressed: _handleCancel,
|
||||
),
|
||||
TextButton(
|
||||
child: Text(widget.confirmText ?? localizations.okButtonLabel),
|
||||
onPressed: _handleOk,
|
||||
),
|
||||
],
|
||||
final Widget actions = Container(
|
||||
alignment: AlignmentDirectional.centerEnd,
|
||||
constraints: const BoxConstraints(minHeight: 52.0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
child: OverflowBar(
|
||||
spacing: 8,
|
||||
children: <Widget>[
|
||||
TextButton(
|
||||
child: Text(widget.cancelText ?? localizations.cancelButtonLabel),
|
||||
onPressed: _handleCancel,
|
||||
),
|
||||
TextButton(
|
||||
child: Text(widget.confirmText ?? localizations.okButtonLabel),
|
||||
onPressed: _handleOk,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget picker;
|
||||
|
|
|
@ -362,6 +362,80 @@ void main() {
|
|||
expect(themeDialogMaterial.elevation, customDialogTheme.elevation);
|
||||
});
|
||||
|
||||
testWidgets('OK Cancel button layout', (WidgetTester tester) async {
|
||||
Widget buildFrame(TextDirection textDirection) {
|
||||
return MaterialApp(
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return ElevatedButton(
|
||||
child: const Text('X'),
|
||||
onPressed: () {
|
||||
showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime(2016, DateTime.january, 15),
|
||||
firstDate:DateTime(2001, DateTime.january, 1),
|
||||
lastDate: DateTime(2031, DateTime.december, 31),
|
||||
builder: (BuildContext context, Widget child) {
|
||||
return Directionality(
|
||||
textDirection: textDirection,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Default landscape layout.
|
||||
|
||||
await tester.pumpWidget(buildFrame(TextDirection.ltr));
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getBottomRight(find.text('OK')).dx, 622);
|
||||
expect(tester.getBottomLeft(find.text('OK')).dx, 594);
|
||||
expect(tester.getBottomRight(find.text('CANCEL')).dx, 560);
|
||||
await tester.tap(find.text('OK'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.pumpWidget(buildFrame(TextDirection.rtl));
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getBottomRight(find.text('OK')).dx, 206);
|
||||
expect(tester.getBottomLeft(find.text('OK')).dx, 178);
|
||||
expect(tester.getBottomRight(find.text('CANCEL')).dx, 324);
|
||||
await tester.tap(find.text('OK'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Portrait layout.
|
||||
|
||||
addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
|
||||
tester.binding.window.physicalSizeTestValue = const Size(900, 1200);
|
||||
|
||||
await tester.pumpWidget(buildFrame(TextDirection.ltr));
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getBottomRight(find.text('OK')).dx, 258);
|
||||
expect(tester.getBottomLeft(find.text('OK')).dx, 230);
|
||||
expect(tester.getBottomRight(find.text('CANCEL')).dx, 196);
|
||||
await tester.tap(find.text('OK'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.pumpWidget(buildFrame(TextDirection.rtl));
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getBottomRight(find.text('OK')).dx, 70);
|
||||
expect(tester.getBottomLeft(find.text('OK')).dx, 42);
|
||||
expect(tester.getBottomRight(find.text('CANCEL')).dx, 188);
|
||||
await tester.tap(find.text('OK'));
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
});
|
||||
|
||||
group('Calendar mode', () {
|
||||
|
|
Loading…
Reference in a new issue