Skip to content

Commit

Permalink
Allow removing/skipping fishing spot when adding a catch #911
Browse files Browse the repository at this point in the history
  • Loading branch information
cohenadair committed Jul 2, 2024
1 parent 6efe502 commit ff54724
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 15 deletions.
1 change: 1 addition & 0 deletions mobile/lib/i18n/english_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Map<String, Map<String, String>> get englishStrings => {
"none": "None",
"all": "All",
"next": "Next",
"skip": "Skip",
"ok": "Ok",
"error": "Error",
"warning": "Warning",
Expand Down
2 changes: 2 additions & 0 deletions mobile/lib/i18n/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Strings {

String get next => _string("next");

String get skip => _string("skip");

String get ok => _string("ok");

String get error => _string("error");
Expand Down
57 changes: 42 additions & 15 deletions mobile/lib/widgets/fishing_spot_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,28 +288,33 @@ class FishingSpotMapState extends State<FishingSpotMap> {
Widget? leading;
Widget? trailing;
if (_isPicking) {
if (_pickerSettings!.onNext != null) {
if (_pickerSettings!.onNext == null) {
trailing = _buildClearButton(
name,
() {
_pickerSettings!.controller.clear();
_selectFishingSpot(null, dismissIfNull: true);
},
);
} else {
trailing = Padding(
padding: insetsRightSmall,
child: ActionButton(
condensed: true,
text: Strings.of(context).next,
textColor: context.colorDefault,
onPressed: () {
_pickerSettings!.controller.value = _activeFishingSpot;
_pickerSettings!.onNext!.call();
},
child: Row(
children: [
_buildPickerActionButton(Strings.of(context).skip, null),
_buildPickerActionButton(
Strings.of(context).next,
_activeFishingSpot,
),
],
),
);
}
leading = const BackButton();
} else {
trailing = AnimatedVisibility(
visible: isNotEmpty(name),
child: IconButton(
icon: const Icon(Icons.clear),
onPressed: () => _selectFishingSpot(null, dismissIfNull: true),
),
trailing = _buildClearButton(
name,
() => _selectFishingSpot(null, dismissIfNull: true),
);
}

Expand Down Expand Up @@ -342,6 +347,28 @@ class FishingSpotMapState extends State<FishingSpotMap> {
);
}

Widget _buildClearButton(String? fishingSpotName, VoidCallback onPressed) {
return AnimatedVisibility(
visible: isNotEmpty(fishingSpotName),
child: IconButton(
icon: const Icon(Icons.clear),
onPressed: onPressed,
),
);
}

Widget _buildPickerActionButton(String label, FishingSpot? pickedSpot) {
return ActionButton(
condensed: true,
text: label,
textColor: context.colorDefault,
onPressed: () {
_pickerSettings!.controller.value = pickedSpot;
_pickerSettings!.onNext!.call();
},
);
}

Widget _buildMapStyleButton() {
if (!widget.showMapTypeButton) {
return const Empty();
Expand Down
45 changes: 45 additions & 0 deletions mobile/test/widget/fishing_spot_map_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,51 @@ void main() {
);

expect(find.text("NEXT"), findsNothing);
expect(find.byIcon(Icons.clear), findsOneWidget);
});

testWidgets("Pick clear button clears picked spot", (tester) async {
var controller = InputController<FishingSpot>();
controller.value = FishingSpot(id: randomId());

await pumpMapWrapper(
tester,
FishingSpotMap(
pickerSettings: FishingSpotMapPickerSettings(
controller: controller,
onNext: null,
),
),
);
expect(controller.hasValue, isTrue);

await tapAndSettle(tester, find.byIcon(Icons.clear));
expect(controller.hasValue, isFalse);
});

testWidgets("Skip picking clears selection", (tester) async {
var controller = InputController<FishingSpot>();
controller.value = FishingSpot(id: randomId());

var invoked = false;

await pumpMapWrapper(
tester,
FishingSpotMap(
pickerSettings: FishingSpotMapPickerSettings(
controller: controller,
onNext: () => invoked = true,
),
),
);

expect(find.text("SKIP"), findsOneWidget);
expect(invoked, isFalse);
expect(controller.hasValue, isTrue);

await tapAndSettle(tester, find.text("SKIP"));
expect(invoked, isTrue);
expect(controller.hasValue, isFalse);
});

testWidgets("Search bar shows clear button when not picking", (tester) async {
Expand Down

0 comments on commit ff54724

Please sign in to comment.