switch
statement cleanup (#148382)
This PR is step 12 in the journey to solve issue #136139 and make the entire Flutter repo more readable. Most of it involves implementing switch expressions, and there's also a few other random things that I wanted to clean up a bit.
This commit is contained in:
parent
c4ad1dc1e9
commit
fa9992eff6
@ -1187,10 +1187,8 @@ Future<void> _runInteractive({
|
|||||||
case 'q':
|
case 'q':
|
||||||
checker.cleanupTempDirectory();
|
checker.cleanupTempDirectory();
|
||||||
exit(0);
|
exit(0);
|
||||||
case 'r':
|
case 'r' when !busy:
|
||||||
if (!busy) {
|
rerun();
|
||||||
rerun();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Watcher(file.absolute.path).events.listen((_) => rerun());
|
Watcher(file.absolute.path).events.listen((_) => rerun());
|
||||||
|
@ -385,23 +385,12 @@ class StartContext extends Context {
|
|||||||
|
|
||||||
/// Determine this release's version number from the [lastVersion] and the [incrementLetter].
|
/// Determine this release's version number from the [lastVersion] and the [incrementLetter].
|
||||||
Version calculateNextVersion(Version lastVersion, ReleaseType releaseType) {
|
Version calculateNextVersion(Version lastVersion, ReleaseType releaseType) {
|
||||||
late final Version nextVersion;
|
return switch (releaseType) {
|
||||||
switch (releaseType) {
|
ReleaseType.STABLE_INITIAL => Version(x: lastVersion.x, y: lastVersion.y, z: 0, type: VersionType.stable),
|
||||||
case ReleaseType.STABLE_INITIAL:
|
ReleaseType.STABLE_HOTFIX => Version.increment(lastVersion, 'z'),
|
||||||
nextVersion = Version(
|
ReleaseType.BETA_INITIAL => Version.fromCandidateBranch(candidateBranch),
|
||||||
x: lastVersion.x,
|
ReleaseType.BETA_HOTFIX || _ => Version.increment(lastVersion, 'n'),
|
||||||
y: lastVersion.y,
|
};
|
||||||
z: 0,
|
|
||||||
type: VersionType.stable,
|
|
||||||
);
|
|
||||||
case ReleaseType.STABLE_HOTFIX:
|
|
||||||
nextVersion = Version.increment(lastVersion, 'z');
|
|
||||||
case ReleaseType.BETA_INITIAL:
|
|
||||||
nextVersion = Version.fromCandidateBranch(candidateBranch);
|
|
||||||
case ReleaseType.BETA_HOTFIX:
|
|
||||||
nextVersion = Version.increment(lastVersion, 'n');
|
|
||||||
}
|
|
||||||
return nextVersion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensures the branch point [candidateBranch] and `master` has a version tag.
|
/// Ensures the branch point [candidateBranch] and `master` has a version tag.
|
||||||
|
@ -115,15 +115,11 @@ class ABTest {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
value = ''.padRight(len);
|
value = ''.padRight(len);
|
||||||
} else {
|
} else {
|
||||||
switch (aligns[column]) {
|
value = switch (aligns[column]) {
|
||||||
case FieldJustification.LEFT:
|
FieldJustification.LEFT => value.padRight(len),
|
||||||
value = value.padRight(len);
|
FieldJustification.RIGHT => value.padLeft(len),
|
||||||
case FieldJustification.RIGHT:
|
FieldJustification.CENTER => value.padLeft((len + value.length) ~/ 2).padRight(len),
|
||||||
value = value.padLeft(len);
|
};
|
||||||
case FieldJustification.CENTER:
|
|
||||||
value = value.padLeft((len + value.length) ~/2);
|
|
||||||
value = value.padRight(len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (column > 0) {
|
if (column > 0) {
|
||||||
value = value.padLeft(len+1);
|
value = value.padLeft(len+1);
|
||||||
|
@ -252,14 +252,11 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> _matchesCPURequirement(AndroidDevice device) async {
|
Future<bool> _matchesCPURequirement(AndroidDevice device) async {
|
||||||
switch (cpu) {
|
return switch (cpu) {
|
||||||
case null:
|
null => Future<bool>.value(true),
|
||||||
return true;
|
AndroidCPU.arm64 => device.isArm64(),
|
||||||
case AndroidCPU.arm64:
|
AndroidCPU.arm => device.isArm(),
|
||||||
return device.isArm64();
|
};
|
||||||
case AndroidCPU.arm:
|
|
||||||
return device.isArm();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Picks a random Android device out of connected devices and sets it as
|
/// Picks a random Android device out of connected devices and sets it as
|
||||||
|
@ -37,19 +37,12 @@ class TestStepResult {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory TestStepResult.fromSnapshot(AsyncSnapshot<TestStepResult> snapshot) {
|
factory TestStepResult.fromSnapshot(AsyncSnapshot<TestStepResult> snapshot) {
|
||||||
switch (snapshot.connectionState) {
|
return switch (snapshot.connectionState) {
|
||||||
case ConnectionState.none:
|
ConnectionState.none => const TestStepResult('Not started', nothing, TestStatus.ok),
|
||||||
return const TestStepResult('Not started', nothing, TestStatus.ok);
|
ConnectionState.waiting => const TestStepResult('Executing', nothing, TestStatus.pending),
|
||||||
case ConnectionState.waiting:
|
ConnectionState.done => snapshot.data ?? snapshot.error! as TestStepResult,
|
||||||
return const TestStepResult('Executing', nothing, TestStatus.pending);
|
ConnectionState.active => throw 'Unsupported state: ConnectionState.active',
|
||||||
case ConnectionState.done:
|
};
|
||||||
if (snapshot.hasData) {
|
|
||||||
return snapshot.data!;
|
|
||||||
}
|
|
||||||
return snapshot.error! as TestStepResult;
|
|
||||||
case ConnectionState.active:
|
|
||||||
throw 'Unsupported state ${snapshot.connectionState}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
|
@ -204,18 +204,12 @@ class _ListDemoState extends State<ListDemo> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final String layoutText = _dense != null ? ' \u2013 Dense' : '';
|
final String layoutText = _dense != null ? ' \u2013 Dense' : '';
|
||||||
String? itemTypeText;
|
final String? itemTypeText = switch (_itemType) {
|
||||||
switch (_itemType) {
|
_MaterialListType.oneLine || _MaterialListType.oneLineWithAvatar => 'Single-line',
|
||||||
case _MaterialListType.oneLine:
|
_MaterialListType.twoLine => 'Two-line',
|
||||||
case _MaterialListType.oneLineWithAvatar:
|
_MaterialListType.threeLine => 'Three-line',
|
||||||
itemTypeText = 'Single-line';
|
null => null,
|
||||||
case _MaterialListType.twoLine:
|
};
|
||||||
itemTypeText = 'Two-line';
|
|
||||||
case _MaterialListType.threeLine:
|
|
||||||
itemTypeText = 'Three-line';
|
|
||||||
case null:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterable<Widget> listTiles = items.map<Widget>((String item) => buildListTile(context, item));
|
Iterable<Widget> listTiles = items.map<Widget>((String item) => buildListTile(context, item));
|
||||||
if (_showDividers != null) {
|
if (_showDividers != null) {
|
||||||
|
@ -80,29 +80,12 @@ class _CustomRangeThumbShape extends RangeSliderThumbShape {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final double size = _thumbSize * sizeTween.evaluate(enableAnimation);
|
final double size = _thumbSize * sizeTween.evaluate(enableAnimation);
|
||||||
late Path thumbPath;
|
final Path thumbPath = switch ((textDirection!, thumb!)) {
|
||||||
switch (textDirection) {
|
(TextDirection.rtl, Thumb.start) => _rightTriangle(size, center),
|
||||||
case TextDirection.rtl:
|
(TextDirection.rtl, Thumb.end) => _leftTriangle(size, center),
|
||||||
switch (thumb) {
|
(TextDirection.ltr, Thumb.start) => _leftTriangle(size, center),
|
||||||
case Thumb.start:
|
(TextDirection.ltr, Thumb.end) => _rightTriangle(size, center),
|
||||||
thumbPath = _rightTriangle(size, center);
|
};
|
||||||
case Thumb.end:
|
|
||||||
thumbPath = _leftTriangle(size, center);
|
|
||||||
case null:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TextDirection.ltr:
|
|
||||||
switch (thumb) {
|
|
||||||
case Thumb.start:
|
|
||||||
thumbPath = _leftTriangle(size, center);
|
|
||||||
case Thumb.end:
|
|
||||||
thumbPath = _rightTriangle(size, center);
|
|
||||||
case null:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case null:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation)!);
|
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation)!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,15 +50,11 @@ enum GalleryDemoCategory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String? displayTitle(GalleryLocalizations localizations) {
|
String? displayTitle(GalleryLocalizations localizations) {
|
||||||
switch (this) {
|
return switch (this) {
|
||||||
case GalleryDemoCategory.other:
|
study => null,
|
||||||
return localizations.homeCategoryReference;
|
material || cupertino => toString(),
|
||||||
case GalleryDemoCategory.material:
|
other => localizations.homeCategoryReference,
|
||||||
case GalleryDemoCategory.cupertino:
|
};
|
||||||
return toString();
|
|
||||||
case GalleryDemoCategory.study:
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,22 +96,15 @@ class GalleryOptions {
|
|||||||
/// In other words, if the theme is dark, returns light; if the theme is
|
/// In other words, if the theme is dark, returns light; if the theme is
|
||||||
/// light, returns dark.
|
/// light, returns dark.
|
||||||
SystemUiOverlayStyle resolvedSystemUiOverlayStyle() {
|
SystemUiOverlayStyle resolvedSystemUiOverlayStyle() {
|
||||||
Brightness brightness;
|
final Brightness brightness = switch (themeMode) {
|
||||||
switch (themeMode) {
|
ThemeMode.light => Brightness.light,
|
||||||
case ThemeMode.light:
|
ThemeMode.dark => Brightness.dark,
|
||||||
brightness = Brightness.light;
|
ThemeMode.system => WidgetsBinding.instance.platformDispatcher.platformBrightness,
|
||||||
case ThemeMode.dark:
|
};
|
||||||
brightness = Brightness.dark;
|
return switch (brightness) {
|
||||||
case ThemeMode.system:
|
Brightness.light => SystemUiOverlayStyle.dark,
|
||||||
brightness =
|
Brightness.dark => SystemUiOverlayStyle.light,
|
||||||
WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
final SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
|
|
||||||
? SystemUiOverlayStyle.light
|
|
||||||
: SystemUiOverlayStyle.dark;
|
|
||||||
|
|
||||||
return overlayStyle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GalleryOptions copyWith({
|
GalleryOptions copyWith({
|
||||||
|
@ -105,18 +105,13 @@ class _CupertinoAlertDemoState extends State<CupertinoAlertDemo>
|
|||||||
|
|
||||||
String _title(BuildContext context) {
|
String _title(BuildContext context) {
|
||||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||||
switch (widget.type) {
|
return switch (widget.type) {
|
||||||
case AlertDemoType.alert:
|
AlertDemoType.alert => localizations.demoCupertinoAlertTitle,
|
||||||
return localizations.demoCupertinoAlertTitle;
|
AlertDemoType.alertTitle => localizations.demoCupertinoAlertWithTitleTitle,
|
||||||
case AlertDemoType.alertTitle:
|
AlertDemoType.alertButtons => localizations.demoCupertinoAlertButtonsTitle,
|
||||||
return localizations.demoCupertinoAlertWithTitleTitle;
|
AlertDemoType.alertButtonsOnly => localizations.demoCupertinoAlertButtonsOnlyTitle,
|
||||||
case AlertDemoType.alertButtons:
|
AlertDemoType.actionSheet => localizations.demoCupertinoActionSheetTitle,
|
||||||
return localizations.demoCupertinoAlertButtonsTitle;
|
};
|
||||||
case AlertDemoType.alertButtonsOnly:
|
|
||||||
return localizations.demoCupertinoAlertButtonsOnlyTitle;
|
|
||||||
case AlertDemoType.actionSheet:
|
|
||||||
return localizations.demoCupertinoActionSheetTitle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Route<String> _alertDemoDialog(
|
static Route<String> _alertDemoDialog(
|
||||||
|
@ -17,21 +17,17 @@ class BottomSheetDemo extends StatelessWidget {
|
|||||||
|
|
||||||
String _title(BuildContext context) {
|
String _title(BuildContext context) {
|
||||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case BottomSheetDemoType.persistent:
|
BottomSheetDemoType.persistent => localizations.demoBottomSheetPersistentTitle,
|
||||||
return localizations.demoBottomSheetPersistentTitle;
|
BottomSheetDemoType.modal => localizations.demoBottomSheetModalTitle,
|
||||||
case BottomSheetDemoType.modal:
|
};
|
||||||
return localizations.demoBottomSheetModalTitle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _bottomSheetDemo(BuildContext context) {
|
Widget _bottomSheetDemo(BuildContext context) {
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case BottomSheetDemoType.persistent:
|
BottomSheetDemoType.persistent => _PersistentBottomSheetDemo(),
|
||||||
return _PersistentBottomSheetDemo();
|
BottomSheetDemoType.modal => _ModalBottomSheetDemo(),
|
||||||
case BottomSheetDemoType.modal:
|
};
|
||||||
return _ModalBottomSheetDemo();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -13,18 +13,13 @@ class ButtonDemo extends StatelessWidget {
|
|||||||
|
|
||||||
String _title(BuildContext context) {
|
String _title(BuildContext context) {
|
||||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case ButtonDemoType.text:
|
ButtonDemoType.text => localizations.demoTextButtonTitle,
|
||||||
return localizations.demoTextButtonTitle;
|
ButtonDemoType.elevated => localizations.demoElevatedButtonTitle,
|
||||||
case ButtonDemoType.elevated:
|
ButtonDemoType.outlined => localizations.demoOutlinedButtonTitle,
|
||||||
return localizations.demoElevatedButtonTitle;
|
ButtonDemoType.toggle => localizations.demoToggleButtonTitle,
|
||||||
case ButtonDemoType.outlined:
|
ButtonDemoType.floating => localizations.demoFloatingButtonTitle,
|
||||||
return localizations.demoOutlinedButtonTitle;
|
};
|
||||||
case ButtonDemoType.toggle:
|
|
||||||
return localizations.demoToggleButtonTitle;
|
|
||||||
case ButtonDemoType.floating:
|
|
||||||
return localizations.demoFloatingButtonTitle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -16,16 +16,12 @@ class ChipDemo extends StatelessWidget {
|
|||||||
|
|
||||||
String _title(BuildContext context) {
|
String _title(BuildContext context) {
|
||||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case ChipDemoType.action:
|
ChipDemoType.action => localizations.demoActionChipTitle,
|
||||||
return localizations.demoActionChipTitle;
|
ChipDemoType.choice => localizations.demoChoiceChipTitle,
|
||||||
case ChipDemoType.choice:
|
ChipDemoType.filter => localizations.demoFilterChipTitle,
|
||||||
return localizations.demoChoiceChipTitle;
|
ChipDemoType.input => localizations.demoInputChipTitle,
|
||||||
case ChipDemoType.filter:
|
};
|
||||||
return localizations.demoFilterChipTitle;
|
|
||||||
case ChipDemoType.input:
|
|
||||||
return localizations.demoInputChipTitle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -81,16 +81,12 @@ class _DialogDemoState extends State<DialogDemo> with RestorationMixin {
|
|||||||
|
|
||||||
String _title(BuildContext context) {
|
String _title(BuildContext context) {
|
||||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||||
switch (widget.type) {
|
return switch (widget.type) {
|
||||||
case DialogDemoType.alert:
|
DialogDemoType.alert => localizations.demoAlertDialogTitle,
|
||||||
return localizations.demoAlertDialogTitle;
|
DialogDemoType.alertTitle => localizations.demoAlertTitleDialogTitle,
|
||||||
case DialogDemoType.alertTitle:
|
DialogDemoType.simple => localizations.demoSimpleDialogTitle,
|
||||||
return localizations.demoAlertTitleDialogTitle;
|
DialogDemoType.fullscreen => localizations.demoFullscreenDialogTitle,
|
||||||
case DialogDemoType.simple:
|
};
|
||||||
return localizations.demoSimpleDialogTitle;
|
|
||||||
case DialogDemoType.fullscreen:
|
|
||||||
return localizations.demoFullscreenDialogTitle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Route<String> _alertDialogDemoRoute(
|
static Route<String> _alertDialogDemoRoute(
|
||||||
|
@ -164,14 +164,11 @@ class _PickerDemoState extends State<PickerDemo> with RestorationMixin {
|
|||||||
|
|
||||||
String get _title {
|
String get _title {
|
||||||
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
final GalleryLocalizations localizations = GalleryLocalizations.of(context)!;
|
||||||
switch (widget.type) {
|
return switch (widget.type) {
|
||||||
case PickerDemoType.date:
|
PickerDemoType.date => localizations.demoDatePickerTitle,
|
||||||
return localizations.demoDatePickerTitle;
|
PickerDemoType.time => localizations.demoTimePickerTitle,
|
||||||
case PickerDemoType.time:
|
PickerDemoType.range => localizations.demoDateRangePickerTitle,
|
||||||
return localizations.demoTimePickerTitle;
|
};
|
||||||
case PickerDemoType.range:
|
|
||||||
return localizations.demoDateRangePickerTitle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String get _labelText {
|
String get _labelText {
|
||||||
|
@ -13,14 +13,10 @@ class TabsDemo extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget tabs;
|
return switch (type) {
|
||||||
switch (type) {
|
TabsDemoType.scrollable => _TabsScrollableDemo(),
|
||||||
case TabsDemoType.scrollable:
|
TabsDemoType.nonScrollable => _TabsNonScrollableDemo(),
|
||||||
tabs = _TabsScrollableDemo();
|
};
|
||||||
case TabsDemoType.nonScrollable:
|
|
||||||
tabs = _TabsNonScrollableDemo();
|
|
||||||
}
|
|
||||||
return tabs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,16 +433,11 @@ class _GalleryDemoPageState extends State<GalleryDemoPage>
|
|||||||
page = AnimatedBuilder(
|
page = AnimatedBuilder(
|
||||||
animation: _codeBackgroundColorController,
|
animation: _codeBackgroundColorController,
|
||||||
builder: (BuildContext context, Widget? child) {
|
builder: (BuildContext context, Widget? child) {
|
||||||
Brightness themeBrightness;
|
final Brightness themeBrightness = switch (GalleryOptions.of(context).themeMode) {
|
||||||
|
ThemeMode.system => MediaQuery.of(context).platformBrightness,
|
||||||
switch (GalleryOptions.of(context).themeMode) {
|
ThemeMode.light => Brightness.light,
|
||||||
case ThemeMode.system:
|
ThemeMode.dark => Brightness.dark,
|
||||||
themeBrightness = MediaQuery.of(context).platformBrightness;
|
};
|
||||||
case ThemeMode.light:
|
|
||||||
themeBrightness = Brightness.light;
|
|
||||||
case ThemeMode.dark:
|
|
||||||
themeBrightness = Brightness.dark;
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget contents = Container(
|
Widget contents = Container(
|
||||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||||
|
@ -89,17 +89,13 @@ class _ReplyAppState extends State<ReplyApp> with RestorationMixin {
|
|||||||
supportedLocales: GalleryLocalizations.supportedLocales,
|
supportedLocales: GalleryLocalizations.supportedLocales,
|
||||||
locale: GalleryOptions.of(context).locale,
|
locale: GalleryOptions.of(context).locale,
|
||||||
initialRoute: ReplyApp.homeRoute,
|
initialRoute: ReplyApp.homeRoute,
|
||||||
onGenerateRoute: (RouteSettings settings) {
|
onGenerateRoute: (RouteSettings settings) => switch (settings.name) {
|
||||||
switch (settings.name) {
|
ReplyApp.homeRoute => MaterialPageRoute<void>(
|
||||||
case ReplyApp.homeRoute:
|
builder: (BuildContext context) => const AdaptiveNav(),
|
||||||
return MaterialPageRoute<void>(
|
settings: settings,
|
||||||
builder: (BuildContext context) => const AdaptiveNav(),
|
),
|
||||||
settings: settings,
|
ReplyApp.composeRoute => ReplyApp.createComposeRoute(settings),
|
||||||
);
|
_ => null,
|
||||||
case ReplyApp.composeRoute:
|
|
||||||
return ReplyApp.createComposeRoute(settings);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -34,40 +34,15 @@ class MailboxBody extends StatelessWidget {
|
|||||||
final String destinationString = destination
|
final String destinationString = destination
|
||||||
.toString()
|
.toString()
|
||||||
.substring(destination.toString().indexOf('.') + 1);
|
.substring(destination.toString().indexOf('.') + 1);
|
||||||
late List<Email> emails;
|
|
||||||
|
|
||||||
switch (destination) {
|
final List<Email> emails = switch (destination) {
|
||||||
case MailboxPageType.inbox:
|
MailboxPageType.inbox => model.inboxEmails,
|
||||||
{
|
MailboxPageType.sent => model.outboxEmails,
|
||||||
emails = model.inboxEmails;
|
MailboxPageType.starred => model.starredEmails,
|
||||||
break;
|
MailboxPageType.trash => model.trashEmails,
|
||||||
}
|
MailboxPageType.spam => model.spamEmails,
|
||||||
case MailboxPageType.sent:
|
MailboxPageType.drafts => model.draftEmails,
|
||||||
{
|
};
|
||||||
emails = model.outboxEmails;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MailboxPageType.starred:
|
|
||||||
{
|
|
||||||
emails = model.starredEmails;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MailboxPageType.trash:
|
|
||||||
{
|
|
||||||
emails = model.trashEmails;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MailboxPageType.spam:
|
|
||||||
{
|
|
||||||
emails = model.spamEmails;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MailboxPageType.drafts:
|
|
||||||
{
|
|
||||||
emails = model.draftEmails;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
bottom: false,
|
bottom: false,
|
||||||
|
@ -16,21 +16,12 @@ class TestStepResult {
|
|||||||
const TestStepResult(this.name, this.description, this.status);
|
const TestStepResult(this.name, this.description, this.status);
|
||||||
|
|
||||||
factory TestStepResult.fromSnapshot(AsyncSnapshot<TestStepResult> snapshot) {
|
factory TestStepResult.fromSnapshot(AsyncSnapshot<TestStepResult> snapshot) {
|
||||||
switch (snapshot.connectionState) {
|
return switch (snapshot.connectionState) {
|
||||||
case ConnectionState.none:
|
ConnectionState.none => const TestStepResult('Not started', nothing, TestStatus.ok),
|
||||||
return const TestStepResult('Not started', nothing, TestStatus.ok);
|
ConnectionState.waiting => const TestStepResult('Executing', nothing, TestStatus.pending),
|
||||||
case ConnectionState.waiting:
|
ConnectionState.done => snapshot.data ?? snapshot.error! as TestStepResult,
|
||||||
return const TestStepResult('Executing', nothing, TestStatus.pending);
|
ConnectionState.active => throw 'Unsupported state: ConnectionState.active',
|
||||||
case ConnectionState.done:
|
};
|
||||||
if (snapshot.hasData) {
|
|
||||||
return snapshot.data!;
|
|
||||||
} else {
|
|
||||||
final Object? result = snapshot.error;
|
|
||||||
return result! as TestStepResult;
|
|
||||||
}
|
|
||||||
case ConnectionState.active:
|
|
||||||
throw 'Unsupported state ${snapshot.connectionState}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
|
@ -325,26 +325,18 @@ enum SourceElementType {
|
|||||||
unknownType,
|
unknownType,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the enun type [SourceElementType] to a human readable string.
|
/// Converts the enum type [SourceElementType] to a human readable string.
|
||||||
String sourceElementTypeAsString(SourceElementType type) {
|
String sourceElementTypeAsString(SourceElementType type) {
|
||||||
switch (type) {
|
return switch (type) {
|
||||||
case SourceElementType.classType:
|
SourceElementType.classType => 'class',
|
||||||
return 'class';
|
SourceElementType.fieldType => 'field',
|
||||||
case SourceElementType.fieldType:
|
SourceElementType.methodType => 'method',
|
||||||
return 'field';
|
SourceElementType.constructorType => 'constructor',
|
||||||
case SourceElementType.methodType:
|
SourceElementType.typedefType => 'typedef',
|
||||||
return 'method';
|
SourceElementType.topLevelVariableType => 'variable',
|
||||||
case SourceElementType.constructorType:
|
SourceElementType.functionType => 'function',
|
||||||
return 'constructor';
|
SourceElementType.unknownType => 'unknown',
|
||||||
case SourceElementType.typedefType:
|
};
|
||||||
return 'typedef';
|
|
||||||
case SourceElementType.topLevelVariableType:
|
|
||||||
return 'variable';
|
|
||||||
case SourceElementType.functionType:
|
|
||||||
return 'function';
|
|
||||||
case SourceElementType.unknownType:
|
|
||||||
return 'unknown';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A class that represents a Dart element in a source file.
|
/// A class that represents a Dart element in a source file.
|
||||||
|
@ -62,29 +62,12 @@ class LocaleInfo implements Comparable<LocaleInfo> {
|
|||||||
/// across various countries. For example, we know Taiwan uses traditional (Hant)
|
/// across various countries. For example, we know Taiwan uses traditional (Hant)
|
||||||
/// script, so it is safe to apply (Hant) to Taiwanese languages.
|
/// script, so it is safe to apply (Hant) to Taiwanese languages.
|
||||||
if (deriveScriptCode && scriptCode == null) {
|
if (deriveScriptCode && scriptCode == null) {
|
||||||
switch (languageCode) {
|
scriptCode = switch ((languageCode, countryCode)) {
|
||||||
case 'zh': {
|
('zh', 'CN' || 'SG' || null) => 'Hans',
|
||||||
if (countryCode == null) {
|
('zh', 'TW' || 'HK' || 'MO') => 'Hant',
|
||||||
scriptCode = 'Hans';
|
('sr', null) => 'Cyrl',
|
||||||
}
|
_ => null,
|
||||||
switch (countryCode) {
|
};
|
||||||
case 'CN':
|
|
||||||
case 'SG':
|
|
||||||
scriptCode = 'Hans';
|
|
||||||
case 'TW':
|
|
||||||
case 'HK':
|
|
||||||
case 'MO':
|
|
||||||
scriptCode = 'Hant';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'sr': {
|
|
||||||
if (countryCode == null) {
|
|
||||||
scriptCode = 'Cyrl';
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Increment length if we were able to assume a scriptCode.
|
// Increment length if we were able to assume a scriptCode.
|
||||||
if (scriptCode != null) {
|
if (scriptCode != null) {
|
||||||
length += 1;
|
length += 1;
|
||||||
|
@ -155,13 +155,12 @@ class CupertinoTextSelectionControls extends TextSelectionControls {
|
|||||||
/// See [TextSelectionControls.getHandleAnchor].
|
/// See [TextSelectionControls.getHandleAnchor].
|
||||||
@override
|
@override
|
||||||
Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) {
|
Offset getHandleAnchor(TextSelectionHandleType type, double textLineHeight) {
|
||||||
final Size handleSize;
|
final Size handleSize = getHandleSize(textLineHeight);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
// The circle is at the top for the left handle, and the anchor point is
|
// The circle is at the top for the left handle, and the anchor point is
|
||||||
// all the way at the bottom of the line.
|
// all the way at the bottom of the line.
|
||||||
case TextSelectionHandleType.left:
|
case TextSelectionHandleType.left:
|
||||||
handleSize = getHandleSize(textLineHeight);
|
|
||||||
return Offset(
|
return Offset(
|
||||||
handleSize.width / 2,
|
handleSize.width / 2,
|
||||||
handleSize.height,
|
handleSize.height,
|
||||||
@ -169,14 +168,12 @@ class CupertinoTextSelectionControls extends TextSelectionControls {
|
|||||||
// The right handle is vertically flipped, and the anchor point is near
|
// The right handle is vertically flipped, and the anchor point is near
|
||||||
// the top of the circle to give slight overlap.
|
// the top of the circle to give slight overlap.
|
||||||
case TextSelectionHandleType.right:
|
case TextSelectionHandleType.right:
|
||||||
handleSize = getHandleSize(textLineHeight);
|
|
||||||
return Offset(
|
return Offset(
|
||||||
handleSize.width / 2,
|
handleSize.width / 2,
|
||||||
handleSize.height - 2 * _kSelectionHandleRadius + _kSelectionHandleOverlap,
|
handleSize.height - 2 * _kSelectionHandleRadius + _kSelectionHandleOverlap,
|
||||||
);
|
);
|
||||||
// A collapsed handle anchors itself so that it's centered.
|
// A collapsed handle anchors itself so that it's centered.
|
||||||
case TextSelectionHandleType.collapsed:
|
case TextSelectionHandleType.collapsed:
|
||||||
handleSize = getHandleSize(textLineHeight);
|
|
||||||
return Offset(
|
return Offset(
|
||||||
handleSize.width / 2,
|
handleSize.width / 2,
|
||||||
textLineHeight + (handleSize.height - textLineHeight) / 2,
|
textLineHeight + (handleSize.height - textLineHeight) / 2,
|
||||||
|
@ -174,10 +174,7 @@ class _CupertinoTextSelectionToolbarButtonState extends State<CupertinoTextSelec
|
|||||||
: CupertinoColors.inactiveGray,
|
: CupertinoColors.inactiveGray,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (widget.buttonItem == null) {
|
switch (widget.buttonItem?.type) {
|
||||||
return textWidget;
|
|
||||||
}
|
|
||||||
switch (widget.buttonItem!.type) {
|
|
||||||
case ContextMenuButtonType.cut:
|
case ContextMenuButtonType.cut:
|
||||||
case ContextMenuButtonType.copy:
|
case ContextMenuButtonType.copy:
|
||||||
case ContextMenuButtonType.paste:
|
case ContextMenuButtonType.paste:
|
||||||
@ -187,6 +184,7 @@ class _CupertinoTextSelectionToolbarButtonState extends State<CupertinoTextSelec
|
|||||||
case ContextMenuButtonType.searchWeb:
|
case ContextMenuButtonType.searchWeb:
|
||||||
case ContextMenuButtonType.share:
|
case ContextMenuButtonType.share:
|
||||||
case ContextMenuButtonType.custom:
|
case ContextMenuButtonType.custom:
|
||||||
|
case null:
|
||||||
return textWidget;
|
return textWidget;
|
||||||
case ContextMenuButtonType.liveTextInput:
|
case ContextMenuButtonType.liveTextInput:
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
|
@ -903,9 +903,7 @@ class _DestinationLayoutAnimationBuilder extends StatelessWidget {
|
|||||||
animation: info.selectedAnimation,
|
animation: info.selectedAnimation,
|
||||||
curve: Curves.easeInOutCubicEmphasized,
|
curve: Curves.easeInOutCubicEmphasized,
|
||||||
reverseCurve: Curves.easeInOutCubicEmphasized.flipped,
|
reverseCurve: Curves.easeInOutCubicEmphasized.flipped,
|
||||||
builder: (BuildContext context, Animation<double> curvedAnimation) {
|
builder: builder,
|
||||||
return builder(context, curvedAnimation);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,14 +370,11 @@ class Draggable<T extends Object> extends StatefulWidget {
|
|||||||
/// recognizing a drag.
|
/// recognizing a drag.
|
||||||
@protected
|
@protected
|
||||||
MultiDragGestureRecognizer createRecognizer(GestureMultiDragStartCallback onStart) {
|
MultiDragGestureRecognizer createRecognizer(GestureMultiDragStartCallback onStart) {
|
||||||
switch (affinity) {
|
return switch (affinity) {
|
||||||
case Axis.horizontal:
|
Axis.horizontal => HorizontalMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter),
|
||||||
return HorizontalMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter)..onStart = onStart;
|
Axis.vertical => VerticalMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter),
|
||||||
case Axis.vertical:
|
null => ImmediateMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter),
|
||||||
return VerticalMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter)..onStart = onStart;
|
}..onStart = onStart;
|
||||||
case null:
|
|
||||||
return ImmediateMultiDragGestureRecognizer(allowedButtonsFilter: allowedButtonsFilter)..onStart = onStart;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -675,12 +675,10 @@ class BouncingScrollPhysics extends ScrollPhysics {
|
|||||||
/// as more of the area past the edge is dragged in (represented by an increasing
|
/// as more of the area past the edge is dragged in (represented by an increasing
|
||||||
/// `overscrollFraction` which starts at 0 when there is no overscroll).
|
/// `overscrollFraction` which starts at 0 when there is no overscroll).
|
||||||
double frictionFactor(double overscrollFraction) {
|
double frictionFactor(double overscrollFraction) {
|
||||||
switch (decelerationRate) {
|
return math.pow(1 - overscrollFraction, 2) * switch (decelerationRate) {
|
||||||
case ScrollDecelerationRate.fast:
|
ScrollDecelerationRate.fast => 0.26,
|
||||||
return 0.26 * math.pow(1 - overscrollFraction, 2);
|
ScrollDecelerationRate.normal => 0.52,
|
||||||
case ScrollDecelerationRate.normal:
|
};
|
||||||
return 0.52 * math.pow(1 - overscrollFraction, 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1724,16 +1724,14 @@ class RawScrollbarState<T extends RawScrollbar> extends State<T> with TickerProv
|
|||||||
// Determines the scroll direction.
|
// Determines the scroll direction.
|
||||||
final AxisDirection scrollDirection;
|
final AxisDirection scrollDirection;
|
||||||
|
|
||||||
switch (position.axisDirection) {
|
switch (axisDirectionToAxis(position.axisDirection)) {
|
||||||
case AxisDirection.up:
|
case Axis.vertical:
|
||||||
case AxisDirection.down:
|
|
||||||
if (details.localPosition.dy > scrollbarPainter._thumbOffset) {
|
if (details.localPosition.dy > scrollbarPainter._thumbOffset) {
|
||||||
scrollDirection = AxisDirection.down;
|
scrollDirection = AxisDirection.down;
|
||||||
} else {
|
} else {
|
||||||
scrollDirection = AxisDirection.up;
|
scrollDirection = AxisDirection.up;
|
||||||
}
|
}
|
||||||
case AxisDirection.left:
|
case Axis.horizontal:
|
||||||
case AxisDirection.right:
|
|
||||||
if (details.localPosition.dx > scrollbarPainter._thumbOffset) {
|
if (details.localPosition.dx > scrollbarPainter._thumbOffset) {
|
||||||
scrollDirection = AxisDirection.right;
|
scrollDirection = AxisDirection.right;
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,18 +22,17 @@ import 'wait.dart';
|
|||||||
mixin DeserializeFinderFactory {
|
mixin DeserializeFinderFactory {
|
||||||
/// Deserializes the finder from JSON generated by [SerializableFinder.serialize].
|
/// Deserializes the finder from JSON generated by [SerializableFinder.serialize].
|
||||||
SerializableFinder deserializeFinder(Map<String, String> json) {
|
SerializableFinder deserializeFinder(Map<String, String> json) {
|
||||||
final String? finderType = json['finderType'];
|
return switch (json['finderType']) {
|
||||||
switch (finderType) {
|
'ByType' => ByType.deserialize(json),
|
||||||
case 'ByType': return ByType.deserialize(json);
|
'ByValueKey' => ByValueKey.deserialize(json),
|
||||||
case 'ByValueKey': return ByValueKey.deserialize(json);
|
'ByTooltipMessage' => ByTooltipMessage.deserialize(json),
|
||||||
case 'ByTooltipMessage': return ByTooltipMessage.deserialize(json);
|
'BySemanticsLabel' => BySemanticsLabel.deserialize(json),
|
||||||
case 'BySemanticsLabel': return BySemanticsLabel.deserialize(json);
|
'ByText' => ByText.deserialize(json),
|
||||||
case 'ByText': return ByText.deserialize(json);
|
'PageBack' => const PageBack(),
|
||||||
case 'PageBack': return const PageBack();
|
'Descendant' => Descendant.deserialize(json, this),
|
||||||
case 'Descendant': return Descendant.deserialize(json, this);
|
'Ancestor' => Ancestor.deserialize(json, this),
|
||||||
case 'Ancestor': return Ancestor.deserialize(json, this);
|
_ => throw DriverError('Unsupported search specification type ${json['finderType']}'),
|
||||||
}
|
};
|
||||||
throw DriverError('Unsupported search specification type $finderType');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,33 +40,31 @@ mixin DeserializeFinderFactory {
|
|||||||
mixin DeserializeCommandFactory {
|
mixin DeserializeCommandFactory {
|
||||||
/// Deserializes the finder from JSON generated by [Command.serialize] or [CommandWithTarget.serialize].
|
/// Deserializes the finder from JSON generated by [Command.serialize] or [CommandWithTarget.serialize].
|
||||||
Command deserializeCommand(Map<String, String> params, DeserializeFinderFactory finderFactory) {
|
Command deserializeCommand(Map<String, String> params, DeserializeFinderFactory finderFactory) {
|
||||||
final String? kind = params['command'];
|
return switch (params['command']) {
|
||||||
switch (kind) {
|
'get_health' => GetHealth.deserialize(params),
|
||||||
case 'get_health': return GetHealth.deserialize(params);
|
'get_layer_tree' => GetLayerTree.deserialize(params),
|
||||||
case 'get_layer_tree': return GetLayerTree.deserialize(params);
|
'get_render_tree' => GetRenderTree.deserialize(params),
|
||||||
case 'get_render_tree': return GetRenderTree.deserialize(params);
|
'enter_text' => EnterText.deserialize(params),
|
||||||
case 'enter_text': return EnterText.deserialize(params);
|
'send_text_input_action' => SendTextInputAction.deserialize(params),
|
||||||
case 'send_text_input_action': return SendTextInputAction.deserialize(params);
|
'get_text' => GetText.deserialize(params, finderFactory),
|
||||||
case 'get_text': return GetText.deserialize(params, finderFactory);
|
'request_data' => RequestData.deserialize(params),
|
||||||
case 'request_data': return RequestData.deserialize(params);
|
'scroll' => Scroll.deserialize(params, finderFactory),
|
||||||
case 'scroll': return Scroll.deserialize(params, finderFactory);
|
'scrollIntoView' => ScrollIntoView.deserialize(params, finderFactory),
|
||||||
case 'scrollIntoView': return ScrollIntoView.deserialize(params, finderFactory);
|
'set_frame_sync' => SetFrameSync.deserialize(params),
|
||||||
case 'set_frame_sync': return SetFrameSync.deserialize(params);
|
'set_semantics' => SetSemantics.deserialize(params),
|
||||||
case 'set_semantics': return SetSemantics.deserialize(params);
|
'set_text_entry_emulation' => SetTextEntryEmulation.deserialize(params),
|
||||||
case 'set_text_entry_emulation': return SetTextEntryEmulation.deserialize(params);
|
'tap' => Tap.deserialize(params, finderFactory),
|
||||||
case 'tap': return Tap.deserialize(params, finderFactory);
|
'waitFor' => WaitFor.deserialize(params, finderFactory),
|
||||||
case 'waitFor': return WaitFor.deserialize(params, finderFactory);
|
'waitForAbsent' => WaitForAbsent.deserialize(params, finderFactory),
|
||||||
case 'waitForAbsent': return WaitForAbsent.deserialize(params, finderFactory);
|
'waitForTappable' => WaitForTappable.deserialize(params, finderFactory),
|
||||||
case 'waitForTappable': return WaitForTappable.deserialize(params, finderFactory);
|
'waitForCondition' => WaitForCondition.deserialize(params),
|
||||||
case 'waitForCondition': return WaitForCondition.deserialize(params);
|
'waitUntilNoTransientCallbacks' => WaitForCondition.deserialize(params),
|
||||||
case 'waitUntilNoTransientCallbacks': return WaitForCondition.deserialize(params);
|
'waitUntilNoPendingFrame' => WaitForCondition.deserialize(params),
|
||||||
case 'waitUntilNoPendingFrame': return WaitForCondition.deserialize(params);
|
'waitUntilFirstFrameRasterized' => WaitForCondition.deserialize(params),
|
||||||
case 'waitUntilFirstFrameRasterized': return WaitForCondition.deserialize(params);
|
'get_semantics_id' => GetSemanticsId.deserialize(params, finderFactory),
|
||||||
case 'get_semantics_id': return GetSemanticsId.deserialize(params, finderFactory);
|
'get_offset' => GetOffset.deserialize(params, finderFactory),
|
||||||
case 'get_offset': return GetOffset.deserialize(params, finderFactory);
|
'get_diagnostics_tree' => GetDiagnosticsTree.deserialize(params, finderFactory),
|
||||||
case 'get_diagnostics_tree': return GetDiagnosticsTree.deserialize(params, finderFactory);
|
final String? kind => throw DriverError('Unsupported command kind $kind'),
|
||||||
}
|
};
|
||||||
|
|
||||||
throw DriverError('Unsupported command kind $kind');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,15 +231,11 @@ class ByValueKey extends SerializableFinder {
|
|||||||
/// Deserializes the finder from JSON generated by [serialize].
|
/// Deserializes the finder from JSON generated by [serialize].
|
||||||
static ByValueKey deserialize(Map<String, String> json) {
|
static ByValueKey deserialize(Map<String, String> json) {
|
||||||
final String keyValueString = json['keyValueString']!;
|
final String keyValueString = json['keyValueString']!;
|
||||||
final String keyValueType = json['keyValueType']!;
|
return switch (json['keyValueType']!) {
|
||||||
switch (keyValueType) {
|
'int' => ByValueKey(int.parse(keyValueString)),
|
||||||
case 'int':
|
'String' => ByValueKey(keyValueString),
|
||||||
return ByValueKey(int.parse(keyValueString));
|
final String keyValueType => throw _createInvalidKeyValueTypeError(keyValueType),
|
||||||
case 'String':
|
};
|
||||||
return ByValueKey(keyValueString);
|
|
||||||
default:
|
|
||||||
throw _createInvalidKeyValueTypeError(keyValueType);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,27 +33,17 @@ import 'wait.dart';
|
|||||||
mixin CreateFinderFactory {
|
mixin CreateFinderFactory {
|
||||||
/// Creates the flutter widget finder from [SerializableFinder].
|
/// Creates the flutter widget finder from [SerializableFinder].
|
||||||
Finder createFinder(SerializableFinder finder) {
|
Finder createFinder(SerializableFinder finder) {
|
||||||
final String finderType = finder.finderType;
|
return switch (finder.finderType) {
|
||||||
switch (finderType) {
|
'ByText' => _createByTextFinder(finder as ByText),
|
||||||
case 'ByText':
|
'ByTooltipMessage' => _createByTooltipMessageFinder(finder as ByTooltipMessage),
|
||||||
return _createByTextFinder(finder as ByText);
|
'BySemanticsLabel' => _createBySemanticsLabelFinder(finder as BySemanticsLabel),
|
||||||
case 'ByTooltipMessage':
|
'ByValueKey' => _createByValueKeyFinder(finder as ByValueKey),
|
||||||
return _createByTooltipMessageFinder(finder as ByTooltipMessage);
|
'ByType' => _createByTypeFinder(finder as ByType),
|
||||||
case 'BySemanticsLabel':
|
'PageBack' => _createPageBackFinder(),
|
||||||
return _createBySemanticsLabelFinder(finder as BySemanticsLabel);
|
'Ancestor' => _createAncestorFinder(finder as Ancestor),
|
||||||
case 'ByValueKey':
|
'Descendant' => _createDescendantFinder(finder as Descendant),
|
||||||
return _createByValueKeyFinder(finder as ByValueKey);
|
final String type => throw DriverError('Unsupported search specification type $type'),
|
||||||
case 'ByType':
|
};
|
||||||
return _createByTypeFinder(finder as ByType);
|
|
||||||
case 'PageBack':
|
|
||||||
return _createPageBackFinder();
|
|
||||||
case 'Ancestor':
|
|
||||||
return _createAncestorFinder(finder as Ancestor);
|
|
||||||
case 'Descendant':
|
|
||||||
return _createDescendantFinder(finder as Descendant);
|
|
||||||
default:
|
|
||||||
throw DriverError('Unsupported search specification type $finderType');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Finder _createByTextFinder(ByText arguments) {
|
Finder _createByTextFinder(ByText arguments) {
|
||||||
@ -87,14 +77,11 @@ mixin CreateFinderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Finder _createByValueKeyFinder(ByValueKey arguments) {
|
Finder _createByValueKeyFinder(ByValueKey arguments) {
|
||||||
switch (arguments.keyValueType) {
|
return switch (arguments.keyValueType) {
|
||||||
case 'int':
|
'int' => find.byKey(ValueKey<int>(arguments.keyValue as int)),
|
||||||
return find.byKey(ValueKey<int>(arguments.keyValue as int));
|
'String' => find.byKey(ValueKey<String>(arguments.keyValue as String)),
|
||||||
case 'String':
|
_ => throw UnimplementedError('Unsupported ByValueKey type: ${arguments.keyValueType}'),
|
||||||
return find.byKey(ValueKey<String>(arguments.keyValue as String));
|
};
|
||||||
default:
|
|
||||||
throw UnimplementedError('Unsupported ByValueKey type: ${arguments.keyValueType}');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Finder _createByTypeFinder(ByType arguments) {
|
Finder _createByTypeFinder(ByType arguments) {
|
||||||
@ -155,33 +142,33 @@ mixin CommandHandlerFactory {
|
|||||||
|
|
||||||
/// Deserializes the finder from JSON generated by [Command.serialize] or [CommandWithTarget.serialize].
|
/// Deserializes the finder from JSON generated by [Command.serialize] or [CommandWithTarget.serialize].
|
||||||
Future<Result> handleCommand(Command command, WidgetController prober, CreateFinderFactory finderFactory) {
|
Future<Result> handleCommand(Command command, WidgetController prober, CreateFinderFactory finderFactory) {
|
||||||
switch (command.kind) {
|
return switch (command.kind) {
|
||||||
case 'get_health': return _getHealth(command);
|
'get_health' => _getHealth(command),
|
||||||
case 'get_layer_tree': return _getLayerTree(command);
|
'get_layer_tree' => _getLayerTree(command),
|
||||||
case 'get_render_tree': return _getRenderTree(command);
|
'get_render_tree' => _getRenderTree(command),
|
||||||
case 'enter_text': return _enterText(command);
|
'enter_text' => _enterText(command),
|
||||||
case 'send_text_input_action': return _sendTextInputAction(command);
|
'send_text_input_action' => _sendTextInputAction(command),
|
||||||
case 'get_text': return _getText(command, finderFactory);
|
'get_text' => _getText(command, finderFactory),
|
||||||
case 'request_data': return _requestData(command);
|
'request_data' => _requestData(command),
|
||||||
case 'scroll': return _scroll(command, prober, finderFactory);
|
'scroll' => _scroll(command, prober, finderFactory),
|
||||||
case 'scrollIntoView': return _scrollIntoView(command, finderFactory);
|
'scrollIntoView' => _scrollIntoView(command, finderFactory),
|
||||||
case 'set_frame_sync': return _setFrameSync(command);
|
'set_frame_sync' => _setFrameSync(command),
|
||||||
case 'set_semantics': return _setSemantics(command);
|
'set_semantics' => _setSemantics(command),
|
||||||
case 'set_text_entry_emulation': return _setTextEntryEmulation(command);
|
'set_text_entry_emulation' => _setTextEntryEmulation(command),
|
||||||
case 'tap': return _tap(command, prober, finderFactory);
|
'tap' => _tap(command, prober, finderFactory),
|
||||||
case 'waitFor': return _waitFor(command, finderFactory);
|
'waitFor' => _waitFor(command, finderFactory),
|
||||||
case 'waitForAbsent': return _waitForAbsent(command, finderFactory);
|
'waitForAbsent' => _waitForAbsent(command, finderFactory),
|
||||||
case 'waitForTappable': return _waitForTappable(command, finderFactory);
|
'waitForTappable' => _waitForTappable(command, finderFactory),
|
||||||
case 'waitForCondition': return _waitForCondition(command);
|
'waitForCondition' => _waitForCondition(command),
|
||||||
case 'waitUntilNoTransientCallbacks': return _waitUntilNoTransientCallbacks(command);
|
'waitUntilNoTransientCallbacks' => _waitUntilNoTransientCallbacks(command),
|
||||||
case 'waitUntilNoPendingFrame': return _waitUntilNoPendingFrame(command);
|
'waitUntilNoPendingFrame' => _waitUntilNoPendingFrame(command),
|
||||||
case 'waitUntilFirstFrameRasterized': return _waitUntilFirstFrameRasterized(command);
|
'waitUntilFirstFrameRasterized' => _waitUntilFirstFrameRasterized(command),
|
||||||
case 'get_semantics_id': return _getSemanticsId(command, finderFactory);
|
'get_semantics_id' => _getSemanticsId(command, finderFactory),
|
||||||
case 'get_offset': return _getOffset(command, finderFactory);
|
'get_offset' => _getOffset(command, finderFactory),
|
||||||
case 'get_diagnostics_tree': return _getDiagnosticsTree(command, finderFactory);
|
'get_diagnostics_tree' => _getDiagnosticsTree(command, finderFactory),
|
||||||
}
|
final String kind => throw DriverError('Unsupported command kind $kind'),
|
||||||
|
};
|
||||||
|
|
||||||
throw DriverError('Unsupported command kind ${command.kind}');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Health> _getHealth(Command command) async => const Health(HealthStatus.ok);
|
Future<Health> _getHealth(Command command) async => const Health(HealthStatus.ok);
|
||||||
@ -342,19 +329,13 @@ mixin CommandHandlerFactory {
|
|||||||
final Finder finder = await waitForElement(finderFactory.createFinder(getOffsetCommand.finder));
|
final Finder finder = await waitForElement(finderFactory.createFinder(getOffsetCommand.finder));
|
||||||
final Element element = finder.evaluate().single;
|
final Element element = finder.evaluate().single;
|
||||||
final RenderBox box = (element.renderObject as RenderBox?)!;
|
final RenderBox box = (element.renderObject as RenderBox?)!;
|
||||||
Offset localPoint;
|
final Offset localPoint = switch (getOffsetCommand.offsetType) {
|
||||||
switch (getOffsetCommand.offsetType) {
|
OffsetType.topLeft => Offset.zero,
|
||||||
case OffsetType.topLeft:
|
OffsetType.topRight => box.size.topRight(Offset.zero),
|
||||||
localPoint = Offset.zero;
|
OffsetType.bottomLeft => box.size.bottomLeft(Offset.zero),
|
||||||
case OffsetType.topRight:
|
OffsetType.bottomRight => box.size.bottomRight(Offset.zero),
|
||||||
localPoint = box.size.topRight(Offset.zero);
|
OffsetType.center => box.size.center(Offset.zero),
|
||||||
case OffsetType.bottomLeft:
|
};
|
||||||
localPoint = box.size.bottomLeft(Offset.zero);
|
|
||||||
case OffsetType.bottomRight:
|
|
||||||
localPoint = box.size.bottomRight(Offset.zero);
|
|
||||||
case OffsetType.center:
|
|
||||||
localPoint = box.size.center(Offset.zero);
|
|
||||||
}
|
|
||||||
final Offset globalPoint = box.localToGlobal(localPoint);
|
final Offset globalPoint = box.localToGlobal(localPoint);
|
||||||
return GetOffsetResult(dx: globalPoint.dx, dy: globalPoint.dy);
|
return GetOffsetResult(dx: globalPoint.dx, dy: globalPoint.dy);
|
||||||
}
|
}
|
||||||
@ -363,13 +344,10 @@ mixin CommandHandlerFactory {
|
|||||||
final GetDiagnosticsTree diagnosticsCommand = command as GetDiagnosticsTree;
|
final GetDiagnosticsTree diagnosticsCommand = command as GetDiagnosticsTree;
|
||||||
final Finder finder = await waitForElement(finderFactory.createFinder(diagnosticsCommand.finder));
|
final Finder finder = await waitForElement(finderFactory.createFinder(diagnosticsCommand.finder));
|
||||||
final Element element = finder.evaluate().single;
|
final Element element = finder.evaluate().single;
|
||||||
DiagnosticsNode diagnosticsNode;
|
final DiagnosticsNode diagnosticsNode = switch (diagnosticsCommand.diagnosticsType) {
|
||||||
switch (diagnosticsCommand.diagnosticsType) {
|
DiagnosticsType.renderObject => element.renderObject!.toDiagnosticsNode(),
|
||||||
case DiagnosticsType.renderObject:
|
DiagnosticsType.widget => element.toDiagnosticsNode(),
|
||||||
diagnosticsNode = element.renderObject!.toDiagnosticsNode();
|
};
|
||||||
case DiagnosticsType.widget:
|
|
||||||
diagnosticsNode = element.toDiagnosticsNode();
|
|
||||||
}
|
|
||||||
return DiagnosticsTreeResult(diagnosticsNode.toJsonMap(DiagnosticsSerializationDelegate(
|
return DiagnosticsTreeResult(diagnosticsNode.toJsonMap(DiagnosticsSerializationDelegate(
|
||||||
subtreeDepth: diagnosticsCommand.subtreeDepth,
|
subtreeDepth: diagnosticsCommand.subtreeDepth,
|
||||||
includeProperties: diagnosticsCommand.includeProperties,
|
includeProperties: diagnosticsCommand.includeProperties,
|
||||||
|
@ -195,19 +195,14 @@ class CombinedCondition extends SerializableWaitCondition {
|
|||||||
|
|
||||||
/// Parses a [SerializableWaitCondition] or its subclass from the given [json] map.
|
/// Parses a [SerializableWaitCondition] or its subclass from the given [json] map.
|
||||||
SerializableWaitCondition _deserialize(Map<String, String> json) {
|
SerializableWaitCondition _deserialize(Map<String, String> json) {
|
||||||
final String conditionName = json['conditionName']!;
|
return switch (json['conditionName']!) {
|
||||||
switch (conditionName) {
|
'NoTransientCallbacksCondition' => NoTransientCallbacks.deserialize(json),
|
||||||
case 'NoTransientCallbacksCondition':
|
'NoPendingFrameCondition' => NoPendingFrame.deserialize(json),
|
||||||
return NoTransientCallbacks.deserialize(json);
|
'FirstFrameRasterizedCondition' => FirstFrameRasterized.deserialize(json),
|
||||||
case 'NoPendingFrameCondition':
|
'NoPendingPlatformMessagesCondition' => NoPendingPlatformMessages.deserialize(json),
|
||||||
return NoPendingFrame.deserialize(json);
|
'CombinedCondition' => CombinedCondition.deserialize(json),
|
||||||
case 'FirstFrameRasterizedCondition':
|
final String condition => throw SerializationException(
|
||||||
return FirstFrameRasterized.deserialize(json);
|
'Unsupported wait condition $condition in the JSON string $json',
|
||||||
case 'NoPendingPlatformMessagesCondition':
|
),
|
||||||
return NoPendingPlatformMessages.deserialize(json);
|
};
|
||||||
case 'CombinedCondition':
|
|
||||||
return CombinedCondition.deserialize(json);
|
|
||||||
}
|
|
||||||
throw SerializationException(
|
|
||||||
'Unsupported wait condition $conditionName in the JSON string $json');
|
|
||||||
}
|
}
|
||||||
|
@ -121,16 +121,12 @@ class ProfilingSummarizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ProfileType _getProfileType(String? eventName) {
|
static ProfileType _getProfileType(String? eventName) {
|
||||||
switch (eventName) {
|
return switch (eventName) {
|
||||||
case _kCpuProfile:
|
_kCpuProfile => ProfileType.CPU,
|
||||||
return ProfileType.CPU;
|
_kGpuProfile => ProfileType.GPU,
|
||||||
case _kGpuProfile:
|
_kMemoryProfile => ProfileType.Memory,
|
||||||
return ProfileType.GPU;
|
_ => throw Exception('Invalid profiling event: $eventName.'),
|
||||||
case _kMemoryProfile:
|
};
|
||||||
return ProfileType.Memory;
|
|
||||||
default:
|
|
||||||
throw Exception('Invalid profiling event: $eventName.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double _getProfileValue(ProfileType profileType, TimelineEvent e) {
|
double _getProfileValue(ProfileType profileType, TimelineEvent e) {
|
||||||
|
@ -601,19 +601,17 @@ const Duration _kPauseBetweenIsolateRefresh = Duration(milliseconds: 100);
|
|||||||
// See `timeline_streams` in
|
// See `timeline_streams` in
|
||||||
// https://github.com/dart-lang/sdk/blob/main/runtime/vm/timeline.cc
|
// https://github.com/dart-lang/sdk/blob/main/runtime/vm/timeline.cc
|
||||||
List<String> _timelineStreamsToString(List<TimelineStream> streams) {
|
List<String> _timelineStreamsToString(List<TimelineStream> streams) {
|
||||||
return streams.map<String>((TimelineStream stream) {
|
return streams.map<String>((TimelineStream stream) => switch (stream) {
|
||||||
switch (stream) {
|
TimelineStream.all => 'all',
|
||||||
case TimelineStream.all: return 'all';
|
TimelineStream.api => 'API',
|
||||||
case TimelineStream.api: return 'API';
|
TimelineStream.dart => 'Dart',
|
||||||
case TimelineStream.compiler: return 'Compiler';
|
TimelineStream.debugger => 'Debugger',
|
||||||
case TimelineStream.compilerVerbose: return 'CompilerVerbose';
|
TimelineStream.embedder => 'Embedder',
|
||||||
case TimelineStream.dart: return 'Dart';
|
TimelineStream.gc => 'GC',
|
||||||
case TimelineStream.debugger: return 'Debugger';
|
TimelineStream.isolate => 'Isolate',
|
||||||
case TimelineStream.embedder: return 'Embedder';
|
TimelineStream.vm => 'VM',
|
||||||
case TimelineStream.gc: return 'GC';
|
TimelineStream.compiler => 'Compiler',
|
||||||
case TimelineStream.isolate: return 'Isolate';
|
TimelineStream.compilerVerbose => 'CompilerVerbose',
|
||||||
case TimelineStream.vm: return 'VM';
|
|
||||||
}
|
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,18 +177,12 @@ class _InternalCombinedCondition implements WaitCondition {
|
|||||||
/// Parses a [WaitCondition] or its subclass from the given serializable [waitCondition].
|
/// Parses a [WaitCondition] or its subclass from the given serializable [waitCondition].
|
||||||
WaitCondition deserializeCondition(SerializableWaitCondition waitCondition) {
|
WaitCondition deserializeCondition(SerializableWaitCondition waitCondition) {
|
||||||
final String conditionName = waitCondition.conditionName;
|
final String conditionName = waitCondition.conditionName;
|
||||||
switch (conditionName) {
|
return switch (conditionName) {
|
||||||
case 'NoTransientCallbacksCondition':
|
'NoTransientCallbacksCondition' => _InternalNoTransientCallbacksCondition.deserialize(waitCondition),
|
||||||
return _InternalNoTransientCallbacksCondition.deserialize(waitCondition);
|
'NoPendingFrameCondition' => _InternalNoPendingFrameCondition.deserialize(waitCondition),
|
||||||
case 'NoPendingFrameCondition':
|
'FirstFrameRasterizedCondition' => _InternalFirstFrameRasterizedCondition.deserialize(waitCondition),
|
||||||
return _InternalNoPendingFrameCondition.deserialize(waitCondition);
|
'NoPendingPlatformMessagesCondition' => _InternalNoPendingPlatformMessagesCondition.deserialize(waitCondition),
|
||||||
case 'FirstFrameRasterizedCondition':
|
'CombinedCondition' => _InternalCombinedCondition.deserialize(waitCondition),
|
||||||
return _InternalFirstFrameRasterizedCondition.deserialize(waitCondition);
|
_ => throw SerializationException('Unsupported wait condition $conditionName in ${waitCondition.serialize()}'),
|
||||||
case 'NoPendingPlatformMessagesCondition':
|
};
|
||||||
return _InternalNoPendingPlatformMessagesCondition.deserialize(waitCondition);
|
|
||||||
case 'CombinedCondition':
|
|
||||||
return _InternalCombinedCondition.deserialize(waitCondition);
|
|
||||||
}
|
|
||||||
throw SerializationException(
|
|
||||||
'Unsupported wait condition $conditionName in ${waitCondition.serialize()}');
|
|
||||||
}
|
}
|
||||||
|
@ -226,12 +226,10 @@ abstract class GlobalMaterialLocalizations implements MaterialLocalizations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String? _formatDayPeriod(TimeOfDay timeOfDay) {
|
String? _formatDayPeriod(TimeOfDay timeOfDay) {
|
||||||
switch (timeOfDay.period) {
|
return switch (timeOfDay.period) {
|
||||||
case DayPeriod.am:
|
DayPeriod.am => anteMeridiemAbbreviation,
|
||||||
return anteMeridiemAbbreviation;
|
DayPeriod.pm => postMeridiemAbbreviation,
|
||||||
case DayPeriod.pm:
|
};
|
||||||
return postMeridiemAbbreviation;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The raw version of [dateRangeStartDateSemanticLabel], with `$formattedDate` verbatim
|
/// The raw version of [dateRangeStartDateSemanticLabel], with `$formattedDate` verbatim
|
||||||
|
@ -353,16 +353,14 @@ class TestDefaultBinaryMessenger extends BinaryMessenger {
|
|||||||
final StreamController<Object?> controller = StreamController<Object?>();
|
final StreamController<Object?> controller = StreamController<Object?>();
|
||||||
addTearDown(controller.close);
|
addTearDown(controller.close);
|
||||||
|
|
||||||
setMockMethodCallHandler(MethodChannel(channel.name, channel.codec), (MethodCall call) async {
|
setMockMethodCallHandler(
|
||||||
switch (call.method) {
|
MethodChannel(channel.name, channel.codec),
|
||||||
case 'listen':
|
(MethodCall call) async => switch (call.method) {
|
||||||
return handler.onListen(call.arguments, MockStreamHandlerEventSink(controller.sink));
|
'listen' => handler.onListen(call.arguments, MockStreamHandlerEventSink(controller.sink)),
|
||||||
case 'cancel':
|
'cancel' => handler.onCancel(call.arguments),
|
||||||
return handler.onCancel(call.arguments);
|
_ => throw UnimplementedError('Method ${call.method} not implemented'),
|
||||||
default:
|
},
|
||||||
throw UnimplementedError('Method ${call.method} not implemented');
|
);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final StreamSubscription<Object?> sub = controller.stream.listen(
|
final StreamSubscription<Object?> sub = controller.stream.listen(
|
||||||
(Object? e) => handlePlatformMessage(
|
(Object? e) => handlePlatformMessage(
|
||||||
|
@ -76,9 +76,7 @@ enum FlutterProjectType implements CliEnum {
|
|||||||
static List<FlutterProjectType> get enabledValues {
|
static List<FlutterProjectType> get enabledValues {
|
||||||
return <FlutterProjectType>[
|
return <FlutterProjectType>[
|
||||||
for (final FlutterProjectType value in values)
|
for (final FlutterProjectType value in values)
|
||||||
if (value == FlutterProjectType.packageFfi) ...<FlutterProjectType>[
|
if (value != FlutterProjectType.packageFfi || featureFlags.isNativeAssetsEnabled)
|
||||||
if (featureFlags.isNativeAssetsEnabled) value
|
|
||||||
] else
|
|
||||||
value,
|
value,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -206,16 +206,12 @@ class DriverTestMessage {
|
|||||||
|
|
||||||
/// Return a DriverTestMessage depending on `status`.
|
/// Return a DriverTestMessage depending on `status`.
|
||||||
static DriverTestMessage fromString(String status) {
|
static DriverTestMessage fromString(String status) {
|
||||||
switch (status) {
|
return switch (status) {
|
||||||
case 'error':
|
'error' => DriverTestMessage.error(),
|
||||||
return DriverTestMessage.error();
|
'pending' => DriverTestMessage.pending(),
|
||||||
case 'pending':
|
'complete' => DriverTestMessage.complete(),
|
||||||
return DriverTestMessage.pending();
|
_ => throw StateError('This type of status does not exist: $status'),
|
||||||
case 'complete':
|
};
|
||||||
return DriverTestMessage.complete();
|
|
||||||
default:
|
|
||||||
throw StateError('This type of status does not exist: $status');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user