mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> This PR removes redundant useMaterial3: true as described in https://github.com/flutter/flutter/issues/162818 *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* - https://github.com/flutter/flutter/issues/162818 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com>
278 lines
8.8 KiB
Dart
278 lines
8.8 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
testWidgets('DrawerButton control test', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: Scaffold(body: DrawerButton(), drawer: Drawer())),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(Drawer), findsNothing);
|
|
|
|
await tester.tap(find.byType(DrawerButton));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(Drawer), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('DrawerButton onPressed overrides default end drawer open behaviour', (
|
|
WidgetTester tester,
|
|
) async {
|
|
bool customCallbackWasCalled = false;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: Center(child: DrawerButton(onPressed: () => customCallbackWasCalled = true)),
|
|
drawer: const Drawer(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(Drawer), findsNothing); // Start off with a closed drawer
|
|
expect(customCallbackWasCalled, false); // customCallbackWasCalled should still be false.
|
|
await tester.tap(find.byType(DrawerButton));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
// Drawer is still closed
|
|
expect(find.byType(Drawer), findsNothing);
|
|
// The custom callback is called, setting customCallbackWasCalled to true.
|
|
expect(customCallbackWasCalled, true);
|
|
});
|
|
|
|
testWidgets('DrawerButton icon', (WidgetTester tester) async {
|
|
final Key androidKey = UniqueKey();
|
|
final Key iOSKey = UniqueKey();
|
|
final Key linuxKey = UniqueKey();
|
|
final Key macOSKey = UniqueKey();
|
|
final Key windowsKey = UniqueKey();
|
|
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Column(
|
|
children: <Widget>[
|
|
Theme(
|
|
data: ThemeData(platform: TargetPlatform.android),
|
|
child: DrawerButtonIcon(key: androidKey),
|
|
),
|
|
Theme(
|
|
data: ThemeData(platform: TargetPlatform.iOS),
|
|
child: DrawerButtonIcon(key: iOSKey),
|
|
),
|
|
Theme(
|
|
data: ThemeData(platform: TargetPlatform.linux),
|
|
child: DrawerButtonIcon(key: linuxKey),
|
|
),
|
|
Theme(
|
|
data: ThemeData(platform: TargetPlatform.macOS),
|
|
child: DrawerButtonIcon(key: macOSKey),
|
|
),
|
|
Theme(
|
|
data: ThemeData(platform: TargetPlatform.windows),
|
|
child: DrawerButtonIcon(key: windowsKey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
final Icon androidIcon = tester.widget(
|
|
find.descendant(of: find.byKey(androidKey), matching: find.byType(Icon)),
|
|
);
|
|
final Icon iOSIcon = tester.widget(
|
|
find.descendant(of: find.byKey(iOSKey), matching: find.byType(Icon)),
|
|
);
|
|
final Icon linuxIcon = tester.widget(
|
|
find.descendant(of: find.byKey(linuxKey), matching: find.byType(Icon)),
|
|
);
|
|
final Icon macOSIcon = tester.widget(
|
|
find.descendant(of: find.byKey(macOSKey), matching: find.byType(Icon)),
|
|
);
|
|
final Icon windowsIcon = tester.widget(
|
|
find.descendant(of: find.byKey(windowsKey), matching: find.byType(Icon)),
|
|
);
|
|
|
|
// All icons for drawer are the same
|
|
expect(iOSIcon.icon == androidIcon.icon, isTrue);
|
|
expect(linuxIcon.icon == androidIcon.icon, isTrue);
|
|
expect(macOSIcon.icon == androidIcon.icon, isTrue);
|
|
expect(windowsIcon.icon == androidIcon.icon, isTrue);
|
|
});
|
|
|
|
testWidgets('DrawerButton color', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: Material(child: DrawerButton(color: Colors.red))),
|
|
);
|
|
|
|
final RichText iconText = tester.firstWidget(
|
|
find.descendant(of: find.byType(DrawerButton), matching: find.byType(RichText)),
|
|
);
|
|
expect(iconText.text.style!.color, Colors.red);
|
|
});
|
|
|
|
testWidgets('DrawerButton color with ButtonStyle', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: Material(
|
|
child: DrawerButton(
|
|
style: ButtonStyle(iconColor: MaterialStatePropertyAll<Color>(Colors.red)),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final RichText iconText = tester.firstWidget(
|
|
find.descendant(of: find.byType(DrawerButton), matching: find.byType(RichText)),
|
|
);
|
|
expect(iconText.text.style!.color, Colors.red);
|
|
});
|
|
|
|
testWidgets('DrawerButton semantics', (WidgetTester tester) async {
|
|
final SemanticsHandle handle = tester.ensureSemantics();
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: Material(child: Center(child: DrawerButton()))),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
final String? expectedLabel;
|
|
switch (defaultTargetPlatform) {
|
|
case TargetPlatform.android:
|
|
expectedLabel = 'Open navigation menu';
|
|
case TargetPlatform.fuchsia:
|
|
case TargetPlatform.iOS:
|
|
case TargetPlatform.linux:
|
|
case TargetPlatform.macOS:
|
|
case TargetPlatform.windows:
|
|
expectedLabel = null;
|
|
}
|
|
expect(
|
|
tester.getSemantics(find.byType(DrawerButton)),
|
|
matchesSemantics(
|
|
tooltip: 'Open navigation menu',
|
|
label: expectedLabel,
|
|
isButton: true,
|
|
hasEnabledState: true,
|
|
isEnabled: true,
|
|
hasTapAction: true,
|
|
hasFocusAction: defaultTargetPlatform != TargetPlatform.iOS,
|
|
isFocusable: true,
|
|
),
|
|
);
|
|
handle.dispose();
|
|
}, variant: TargetPlatformVariant.all());
|
|
|
|
testWidgets('EndDrawerButton control test', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: Scaffold(body: EndDrawerButton(), endDrawer: Drawer())),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(Drawer), findsNothing);
|
|
|
|
await tester.tap(find.byType(EndDrawerButton));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.byType(Drawer), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('EndDrawerButton semantics', (WidgetTester tester) async {
|
|
final SemanticsHandle handle = tester.ensureSemantics();
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: Material(child: Center(child: EndDrawerButton()))),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
final String? expectedLabel;
|
|
switch (defaultTargetPlatform) {
|
|
case TargetPlatform.android:
|
|
expectedLabel = 'Open navigation menu';
|
|
case TargetPlatform.fuchsia:
|
|
case TargetPlatform.iOS:
|
|
case TargetPlatform.linux:
|
|
case TargetPlatform.macOS:
|
|
case TargetPlatform.windows:
|
|
expectedLabel = null;
|
|
}
|
|
expect(
|
|
tester.getSemantics(find.byType(EndDrawerButton)),
|
|
matchesSemantics(
|
|
tooltip: 'Open navigation menu',
|
|
label: expectedLabel,
|
|
isButton: true,
|
|
hasEnabledState: true,
|
|
isEnabled: true,
|
|
hasTapAction: true,
|
|
hasFocusAction: defaultTargetPlatform != TargetPlatform.iOS,
|
|
isFocusable: true,
|
|
),
|
|
);
|
|
handle.dispose();
|
|
}, variant: TargetPlatformVariant.all());
|
|
|
|
testWidgets('EndDrawerButton color', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(home: Material(child: EndDrawerButton(color: Colors.red))),
|
|
);
|
|
|
|
final RichText iconText = tester.firstWidget(
|
|
find.descendant(of: find.byType(EndDrawerButton), matching: find.byType(RichText)),
|
|
);
|
|
expect(iconText.text.style!.color, Colors.red);
|
|
});
|
|
|
|
testWidgets('EndDrawerButton color with ButtonStyle', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const MaterialApp(
|
|
home: Material(
|
|
child: EndDrawerButton(
|
|
style: ButtonStyle(iconColor: MaterialStatePropertyAll<Color>(Colors.red)),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
final RichText iconText = tester.firstWidget(
|
|
find.descendant(of: find.byType(EndDrawerButton), matching: find.byType(RichText)),
|
|
);
|
|
expect(iconText.text.style!.color, Colors.red);
|
|
});
|
|
|
|
testWidgets('EndDrawerButton onPressed overrides default end drawer open behaviour', (
|
|
WidgetTester tester,
|
|
) async {
|
|
bool customCallbackWasCalled = false;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: Center(child: EndDrawerButton(onPressed: () => customCallbackWasCalled = true)),
|
|
endDrawer: const Drawer(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(Drawer), findsNothing); // Start off with a closed drawer
|
|
expect(customCallbackWasCalled, false); // customCallbackWasCalled should still be false.
|
|
await tester.tap(find.byType(EndDrawerButton));
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
// Drawer is still closed
|
|
expect(find.byType(Drawer), findsNothing);
|
|
// The custom callback is called, setting customCallbackWasCalled to true.
|
|
expect(customCallbackWasCalled, true);
|
|
});
|
|
}
|