Keep message translation sheet below top safe area
This commit is contained in:
1 parent
9ac915bdf2
commit
86dd9d3560
2 files changed
+454
-88
No files matched your search
@@ -1,7 +1,10 @@
|
|||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../l10n/l10n.dart';
|
import '../l10n/l10n.dart';
|
||||||
import '../models/translation_support.dart';
|
import '../models/translation_support.dart';
|
||||||
|
import 'mesh_ui.dart';
|
||||||
|
|
||||||
class MessageTranslationButton extends StatelessWidget {
|
class MessageTranslationButton extends StatelessWidget {
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
@@ -38,15 +41,58 @@ Future<void> showMessageTranslationSheet({
|
|||||||
required ValueChanged<bool> onEnabledChanged,
|
required ValueChanged<bool> onEnabledChanged,
|
||||||
required ValueChanged<String?> onLanguageSelected,
|
required ValueChanged<String?> onLanguageSelected,
|
||||||
}) {
|
}) {
|
||||||
return showModalBottomSheet<void>(
|
final callerMedia = MediaQuery.of(context);
|
||||||
context: context,
|
final navMedia =
|
||||||
isScrollControlled: true,
|
MediaQuery.maybeOf(Navigator.of(context).context) ?? callerMedia;
|
||||||
builder: (context) => _MessageTranslationSheet(
|
final callerBottom = math.max(
|
||||||
enabled: enabled,
|
callerMedia.viewInsets.bottom,
|
||||||
selectedLanguageCode: selectedLanguageCode,
|
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
||||||
onEnabledChanged: onEnabledChanged,
|
);
|
||||||
onLanguageSelected: onLanguageSelected,
|
final navBottom = math.max(
|
||||||
),
|
navMedia.viewInsets.bottom,
|
||||||
|
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
||||||
|
);
|
||||||
|
final extraBottom = math.max(0.0, callerBottom - navBottom);
|
||||||
|
final safeTop = math.max(
|
||||||
|
math.max(callerMedia.viewPadding.top, callerMedia.padding.top),
|
||||||
|
math.max(navMedia.viewPadding.top, navMedia.padding.top),
|
||||||
|
);
|
||||||
|
final bottomSafeInset = math.max(
|
||||||
|
math.max(callerMedia.viewPadding.bottom, callerMedia.padding.bottom),
|
||||||
|
math.max(navMedia.viewPadding.bottom, navMedia.padding.bottom),
|
||||||
|
);
|
||||||
|
|
||||||
|
return showMeshSheet<void>(
|
||||||
|
context,
|
||||||
|
builder: (sheetContext) {
|
||||||
|
final sheetMedia = MediaQuery.of(sheetContext);
|
||||||
|
final screenHeight = math.min(
|
||||||
|
callerMedia.size.height,
|
||||||
|
sheetMedia.size.height,
|
||||||
|
);
|
||||||
|
final maxSheetHeight = math.max(
|
||||||
|
0.0,
|
||||||
|
math.min(
|
||||||
|
screenHeight * 0.82 - bottomSafeInset,
|
||||||
|
screenHeight - safeTop - math.max(callerBottom, navBottom),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return MediaQuery(
|
||||||
|
data: sheetMedia.copyWith(textScaler: callerMedia.textScaler),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(bottom: extraBottom),
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(maxHeight: maxSheetHeight),
|
||||||
|
child: _MessageTranslationSheet(
|
||||||
|
enabled: enabled,
|
||||||
|
selectedLanguageCode: selectedLanguageCode,
|
||||||
|
onEnabledChanged: onEnabledChanged,
|
||||||
|
onLanguageSelected: onLanguageSelected,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +115,8 @@ class _MessageTranslationSheet extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MessageTranslationSheetState extends State<_MessageTranslationSheet> {
|
class _MessageTranslationSheetState extends State<_MessageTranslationSheet> {
|
||||||
|
final GlobalKey _switchKey = GlobalKey();
|
||||||
|
final GlobalKey _searchKey = GlobalKey();
|
||||||
late final TextEditingController _searchController;
|
late final TextEditingController _searchController;
|
||||||
late bool _localEnabled;
|
late bool _localEnabled;
|
||||||
late String? _localSelectedLanguageCode;
|
late String? _localSelectedLanguageCode;
|
||||||
@@ -98,95 +146,166 @@ class _MessageTranslationSheetState extends State<_MessageTranslationSheet> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildSwitchTile(BuildContext context) {
|
||||||
|
return KeyedSubtree(
|
||||||
|
key: _switchKey,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
child: SwitchListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
title: Text(context.l10n.translation_translateBeforeSending),
|
||||||
|
subtitle: Text(
|
||||||
|
_localEnabled
|
||||||
|
? context.l10n.translation_composerEnabledHint
|
||||||
|
: context.l10n.translation_composerDisabledHint,
|
||||||
|
),
|
||||||
|
value: _localEnabled,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() => _localEnabled = value);
|
||||||
|
widget.onEnabledChanged(value);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildSearchField(BuildContext context) {
|
||||||
|
return KeyedSubtree(
|
||||||
|
key: _searchKey,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
|
||||||
|
child: TextField(
|
||||||
|
controller: _searchController,
|
||||||
|
onChanged: _updateFilter,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: context.l10n.translation_targetLanguage,
|
||||||
|
prefixIcon: const Icon(Icons.search),
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildLanguageTile(BuildContext context, int index) {
|
||||||
|
if (index == 0) {
|
||||||
|
final selected = _localSelectedLanguageCode == null;
|
||||||
|
return ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
leading: Icon(
|
||||||
|
selected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
||||||
|
),
|
||||||
|
title: Text(context.l10n.translation_useAppLanguage),
|
||||||
|
onTap: () {
|
||||||
|
setState(() => _localSelectedLanguageCode = null);
|
||||||
|
widget.onLanguageSelected(null);
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final option = _filtered[index - 1];
|
||||||
|
final selected = option.code == _localSelectedLanguageCode;
|
||||||
|
return ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
||||||
|
leading: Icon(
|
||||||
|
selected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
||||||
|
),
|
||||||
|
title: Text(option.label),
|
||||||
|
subtitle: Text(option.code.toUpperCase()),
|
||||||
|
onTap: () {
|
||||||
|
setState(() => _localSelectedLanguageCode = option.code);
|
||||||
|
widget.onLanguageSelected(option.code);
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
final header = BottomSheetHeader(
|
||||||
child: Padding(
|
title: context.l10n.translation_messageTranslation,
|
||||||
padding: EdgeInsets.only(
|
);
|
||||||
left: 16,
|
final switchTile = _buildSwitchTile(context);
|
||||||
right: 16,
|
final searchField = _buildSearchField(context);
|
||||||
top: 16,
|
final itemCount = _filtered.length + 1;
|
||||||
bottom: 16 + MediaQuery.of(context).viewInsets.bottom,
|
|
||||||
),
|
return LayoutBuilder(
|
||||||
child: Column(
|
builder: (context, constraints) {
|
||||||
|
final scaler = MediaQuery.textScalerOf(context);
|
||||||
|
final narrow = constraints.maxWidth < 360;
|
||||||
|
final minPinnedHeight = scaler.scale(narrow ? 360 : 300);
|
||||||
|
|
||||||
|
if (constraints.maxHeight < scaler.scale(150)) {
|
||||||
|
return CustomScrollView(
|
||||||
|
shrinkWrap: true,
|
||||||
|
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||||
|
slivers: [
|
||||||
|
SliverToBoxAdapter(child: header),
|
||||||
|
SliverToBoxAdapter(child: switchTile),
|
||||||
|
SliverToBoxAdapter(child: searchField),
|
||||||
|
SliverPadding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
|
sliver: SliverList.list(
|
||||||
|
children: [
|
||||||
|
for (var i = 0; i < itemCount; i++)
|
||||||
|
_buildLanguageTile(context, i),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (constraints.maxHeight < minPinnedHeight) {
|
||||||
|
return Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
header,
|
||||||
|
Flexible(
|
||||||
|
child: CustomScrollView(
|
||||||
|
shrinkWrap: true,
|
||||||
|
keyboardDismissBehavior:
|
||||||
|
ScrollViewKeyboardDismissBehavior.onDrag,
|
||||||
|
slivers: [
|
||||||
|
SliverToBoxAdapter(child: switchTile),
|
||||||
|
SliverToBoxAdapter(child: searchField),
|
||||||
|
SliverPadding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
|
sliver: SliverList.list(
|
||||||
|
children: [
|
||||||
|
for (var i = 0; i < itemCount; i++)
|
||||||
|
_buildLanguageTile(context, i),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
header,
|
||||||
context.l10n.translation_messageTranslation,
|
switchTile,
|
||||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
searchField,
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
SwitchListTile(
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
title: Text(context.l10n.translation_translateBeforeSending),
|
|
||||||
subtitle: Text(
|
|
||||||
_localEnabled
|
|
||||||
? context.l10n.translation_composerEnabledHint
|
|
||||||
: context.l10n.translation_composerDisabledHint,
|
|
||||||
),
|
|
||||||
value: _localEnabled,
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() => _localEnabled = value);
|
|
||||||
widget.onEnabledChanged(value);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
TextField(
|
|
||||||
controller: _searchController,
|
|
||||||
onChanged: _updateFilter,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
labelText: context.l10n.translation_targetLanguage,
|
|
||||||
prefixIcon: const Icon(Icons.search),
|
|
||||||
border: const OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
Flexible(
|
Flexible(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: _filtered.length + 1,
|
keyboardDismissBehavior:
|
||||||
itemBuilder: (context, index) {
|
ScrollViewKeyboardDismissBehavior.onDrag,
|
||||||
if (index == 0) {
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
final selected = _localSelectedLanguageCode == null;
|
itemCount: itemCount,
|
||||||
return ListTile(
|
itemBuilder: _buildLanguageTile,
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
leading: Icon(
|
|
||||||
selected
|
|
||||||
? Icons.radio_button_checked
|
|
||||||
: Icons.radio_button_unchecked,
|
|
||||||
),
|
|
||||||
title: Text(context.l10n.translation_useAppLanguage),
|
|
||||||
onTap: () {
|
|
||||||
setState(() => _localSelectedLanguageCode = null);
|
|
||||||
widget.onLanguageSelected(null);
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final option = _filtered[index - 1];
|
|
||||||
final selected = option.code == _localSelectedLanguageCode;
|
|
||||||
return ListTile(
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
leading: Icon(
|
|
||||||
selected
|
|
||||||
? Icons.radio_button_checked
|
|
||||||
: Icons.radio_button_unchecked,
|
|
||||||
),
|
|
||||||
title: Text(option.label),
|
|
||||||
subtitle: Text(option.code.toUpperCase()),
|
|
||||||
onTap: () {
|
|
||||||
setState(() => _localSelectedLanguageCode = option.code);
|
|
||||||
widget.onLanguageSelected(option.code);
|
|
||||||
Navigator.pop(context);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,247 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:meshcore_open/l10n/app_localizations.dart';
|
||||||
|
import 'package:meshcore_open/l10n/app_localizations_en.dart';
|
||||||
|
import 'package:meshcore_open/theme/mesh_theme.dart';
|
||||||
|
import 'package:meshcore_open/widgets/mesh_ui.dart';
|
||||||
|
import 'package:meshcore_open/widgets/message_translation_button.dart';
|
||||||
|
|
||||||
|
final _l10n = AppLocalizationsEn();
|
||||||
|
|
||||||
|
Future<void> _openSheet(
|
||||||
|
WidgetTester tester, {
|
||||||
|
Size size = const Size(400, 800),
|
||||||
|
EdgeInsets padding = const EdgeInsets.only(top: 48, bottom: 34),
|
||||||
|
EdgeInsets viewPadding = const EdgeInsets.only(top: 48, bottom: 34),
|
||||||
|
EdgeInsets viewInsets = EdgeInsets.zero,
|
||||||
|
double textScale = 1.0,
|
||||||
|
bool initialEnabled = false,
|
||||||
|
String? initialLanguageCode,
|
||||||
|
ValueChanged<bool>? onEnabledChanged,
|
||||||
|
ValueChanged<String?>? onLanguageSelected,
|
||||||
|
}) async {
|
||||||
|
tester.view.physicalSize = size;
|
||||||
|
tester.view.devicePixelRatio = 1.0;
|
||||||
|
tester.view.padding = FakeViewPadding(
|
||||||
|
left: padding.left,
|
||||||
|
top: padding.top,
|
||||||
|
right: padding.right,
|
||||||
|
bottom: padding.bottom,
|
||||||
|
);
|
||||||
|
tester.view.viewPadding = FakeViewPadding(
|
||||||
|
left: viewPadding.left,
|
||||||
|
top: viewPadding.top,
|
||||||
|
right: viewPadding.right,
|
||||||
|
bottom: viewPadding.bottom,
|
||||||
|
);
|
||||||
|
tester.view.viewInsets = FakeViewPadding(
|
||||||
|
left: viewInsets.left,
|
||||||
|
top: viewInsets.top,
|
||||||
|
right: viewInsets.right,
|
||||||
|
bottom: viewInsets.bottom,
|
||||||
|
);
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
addTearDown(tester.view.resetPadding);
|
||||||
|
addTearDown(tester.view.resetViewPadding);
|
||||||
|
addTearDown(tester.view.resetViewInsets);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: MeshTheme.light(),
|
||||||
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
|
builder: (context, child) {
|
||||||
|
final media = MediaQuery.of(context);
|
||||||
|
return MediaQuery(
|
||||||
|
data: media.copyWith(
|
||||||
|
size: size,
|
||||||
|
padding: padding,
|
||||||
|
viewPadding: viewPadding,
|
||||||
|
viewInsets: viewInsets,
|
||||||
|
textScaler: TextScaler.linear(textScale),
|
||||||
|
),
|
||||||
|
child: child!,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
home: Builder(
|
||||||
|
builder: (context) => Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: MessageTranslationButton(
|
||||||
|
enabled: initialEnabled,
|
||||||
|
languageCode: initialLanguageCode,
|
||||||
|
onPressed: () => showMessageTranslationSheet(
|
||||||
|
context: context,
|
||||||
|
enabled: initialEnabled,
|
||||||
|
selectedLanguageCode: initialLanguageCode,
|
||||||
|
onEnabledChanged: onEnabledChanged ?? (_) {},
|
||||||
|
onLanguageSelected: onLanguageSelected ?? (_) {},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.byType(MessageTranslationButton));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets(
|
||||||
|
'sheet respects top safe area, caps height at <= 85%, and shrinks when filtered',
|
||||||
|
(tester) async {
|
||||||
|
const screenSize = Size(400, 800);
|
||||||
|
await _openSheet(
|
||||||
|
tester,
|
||||||
|
size: screenSize,
|
||||||
|
padding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||||
|
viewPadding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.byType(BottomSheetHeader), findsOneWidget);
|
||||||
|
expect(find.text(_l10n.translation_messageTranslation), findsOneWidget);
|
||||||
|
|
||||||
|
final sheetFinder = find.byType(BottomSheet);
|
||||||
|
final sheetRect = tester.getRect(sheetFinder);
|
||||||
|
final titleTop = tester
|
||||||
|
.getTopLeft(find.text(_l10n.translation_messageTranslation))
|
||||||
|
.dy;
|
||||||
|
|
||||||
|
// Top edge must stay well below the 48px Android status bar inset.
|
||||||
|
expect(sheetRect.top, greaterThan(48.0));
|
||||||
|
expect(sheetRect.top, greaterThanOrEqualTo(screenSize.height * 0.15));
|
||||||
|
expect(sheetRect.height, lessThanOrEqualTo(screenSize.height * 0.85));
|
||||||
|
expect(titleTop - sheetRect.top, inInclusiveRange(16.0, 36.0));
|
||||||
|
|
||||||
|
final unfilteredHeight = sheetRect.height;
|
||||||
|
|
||||||
|
// Filtering down to a single language shrinks the sheet naturally.
|
||||||
|
await tester.enterText(find.byType(TextField), 'Spanish');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final filteredRect = tester.getRect(sheetFinder);
|
||||||
|
expect(filteredRect.height, lessThan(unfilteredHeight));
|
||||||
|
expect(filteredRect.top, greaterThan(sheetRect.top));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'toggling switch, filtering languages, and selecting target or app language works',
|
||||||
|
(tester) async {
|
||||||
|
bool? latestEnabled;
|
||||||
|
String? latestLanguage = 'fr';
|
||||||
|
|
||||||
|
await _openSheet(
|
||||||
|
tester,
|
||||||
|
initialEnabled: false,
|
||||||
|
initialLanguageCode: latestLanguage,
|
||||||
|
onEnabledChanged: (value) => latestEnabled = value,
|
||||||
|
onLanguageSelected: (code) => latestLanguage = code,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.text(_l10n.translation_composerDisabledHint), findsOneWidget);
|
||||||
|
|
||||||
|
await tester.tap(
|
||||||
|
find.widgetWithText(
|
||||||
|
SwitchListTile,
|
||||||
|
_l10n.translation_translateBeforeSending,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(latestEnabled, isTrue);
|
||||||
|
expect(find.text(_l10n.translation_composerEnabledHint), findsOneWidget);
|
||||||
|
|
||||||
|
// Filter by language name and select Spanish ('es').
|
||||||
|
await tester.enterText(find.byType(TextField), 'Spanish');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.widgetWithText(ListTile, 'Spanish'), findsOneWidget);
|
||||||
|
expect(find.widgetWithText(ListTile, 'German'), findsNothing);
|
||||||
|
|
||||||
|
await tester.tap(find.widgetWithText(ListTile, 'Spanish'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(latestLanguage, 'es');
|
||||||
|
expect(find.byType(BottomSheet), findsNothing);
|
||||||
|
|
||||||
|
// Re-open and select "Use app language" (null).
|
||||||
|
await tester.tap(find.byType(MessageTranslationButton));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(
|
||||||
|
find.widgetWithText(ListTile, _l10n.translation_useAppLanguage),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(latestLanguage, isNull);
|
||||||
|
expect(find.byType(BottomSheet), findsNothing);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'avoids layout overflow at 320dp width with 1.3x and 2.0x text scale and keyboard insets',
|
||||||
|
(tester) async {
|
||||||
|
for (final textScale in [1.0, 1.3, 2.0]) {
|
||||||
|
for (final keyboardInset in [0.0, 300.0]) {
|
||||||
|
bool? toggled;
|
||||||
|
String? chosenLanguage;
|
||||||
|
|
||||||
|
await _openSheet(
|
||||||
|
tester,
|
||||||
|
size: const Size(320, 568),
|
||||||
|
padding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||||
|
viewPadding: const EdgeInsets.only(top: 48, bottom: 34),
|
||||||
|
viewInsets: EdgeInsets.only(bottom: keyboardInset),
|
||||||
|
textScale: textScale,
|
||||||
|
onEnabledChanged: (value) => toggled = value,
|
||||||
|
onLanguageSelected: (code) => chosenLanguage = code,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
|
||||||
|
final sheetRect = tester.getRect(find.byType(BottomSheet));
|
||||||
|
expect(sheetRect.top, greaterThanOrEqualTo(48.0));
|
||||||
|
|
||||||
|
await Scrollable.ensureVisible(
|
||||||
|
tester.element(find.byType(Switch)),
|
||||||
|
alignment: 0.5,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(find.byType(Switch));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
expect(toggled, isTrue);
|
||||||
|
|
||||||
|
await Scrollable.ensureVisible(
|
||||||
|
tester.element(find.byType(TextField)),
|
||||||
|
alignment: 0.5,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.enterText(find.byType(TextField), 'de');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
|
||||||
|
final germanTile = find.widgetWithText(
|
||||||
|
ListTile,
|
||||||
|
'German',
|
||||||
|
skipOffstage: false,
|
||||||
|
);
|
||||||
|
await Scrollable.ensureVisible(
|
||||||
|
tester.element(germanTile),
|
||||||
|
alignment: 0.5,
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await tester.tap(germanTile);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(tester.takeException(), isNull);
|
||||||
|
expect(chosenLanguage, 'de');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user