diet-guard/app/test/pickers/picker_test_support.dart
Krzysztof kuhy Rudnicki 49144a2c49 Move the app to material_ui for Flutter 3.50
Flutter 3.50 deprecates package:flutter/material.dart; 73 deprecation
infos failed flutter analyze --fatal-infos, and four Dart pins were
behind (crdt_sync_flutter 0.8.2, flutter_local_notifications 23.0.2,
github_device_auth 0.5.0, sync_settings_ui 0.8.2). Those UI packages
now sit on material_ui, so the app has to as well or their widgets lose
MaterialLocalizations.

Imports swap one-for-one and dart fix re-sorted the directives; no
behaviour change. analyze is clean and all six test shards pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWWfb63jncj9Lca2jeX
2026-11-16 09:25:34 +01:00

85 lines
2.6 KiB
Dart

// Shared helpers for the picker widget tests: open a dialog from a button and
// read back what it popped, and find cells by state rather than by text.
import 'package:diet_guard_app/widgets/pickers/numeral_cell.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import '../label_finders.dart';
/// What a dialog popped: [closed] turns true once it is gone.
class Popped {
/// The popped value (null when cancelled).
Object? value;
/// Whether the dialog has closed.
bool closed = false;
}
/// Pumps an app whose one button opens [dialog]; taps it and settles.
Future<Popped> openDialog(
WidgetTester tester,
Widget dialog, {
Size size = const Size(500, 900),
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final popped = Popped();
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Builder(
builder: (context) => IconButton(
icon: const Icon(Icons.add, semanticLabel: 'open'),
onPressed: () async {
popped
..value = await showDialog<Object>(
context: context,
builder: (_) => dialog,
)
..closed = true;
},
),
),
),
),
);
await tester.tap(byIconLabel('open'));
await tester.pumpAndSettle();
return popped;
}
/// The cell keyed [key] (a `DateTime` day, or `'month-<m>'`).
NumeralCell cell(WidgetTester tester, Object key) => tester.widget<NumeralCell>(
find.byKey(
key is DateTime ? ValueKey<DateTime>(key) : ValueKey<String>('$key'),
),
);
/// The check button, enabled or not.
IconButton confirmButton(WidgetTester tester) => tester.widget<IconButton>(
find.ancestor(of: byIconLabel('Confirm'), matching: find.byType(IconButton)),
);
/// Scrolls the open time dialog's wheels to [hour] and [minute] (a disabled
/// value springs back) and settles. Does not confirm.
Future<void> setWheels(WidgetTester tester, int hour, int minute) async {
for (final (key, value) in [('hour', hour), ('minute', minute)]) {
final wheel = tester.widget<ListWheelScrollView>(
find.descendant(
of: find.byKey(ValueKey(key)),
matching: find.byType(ListWheelScrollView),
),
);
(wheel.controller! as FixedExtentScrollController).jumpToItem(value);
await tester.pumpAndSettle();
}
}
/// Taps the check and settles.
Future<void> confirm(WidgetTester tester) async {
await tester.tap(controlByLabel('Confirm'));
await tester.pumpAndSettle();
}