Skip to content

Commit

Permalink
fix lack of local history update on controller changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hcbpassos committed Aug 29, 2023
1 parent 7cf48ca commit e884158
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
20 changes: 18 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
Expand All @@ -17,13 +18,14 @@

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
pubspec.lock
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/
/build/

# Android related
**/android/**/gradle-wrapper.jar
Expand Down Expand Up @@ -61,6 +63,20 @@ build/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
Expand Down
4 changes: 0 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
linter:
rules:
- prefer_typing_uninitialized_variables
Expand Down
24 changes: 22 additions & 2 deletions example/.metadata
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: 8661d8aecd626f7f57ccbcb735553edc05a2e713
revision: f1875d570e39de09040c8f79aa13cc56baab8db1
channel: unknown

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
- platform: macos
create_revision: f1875d570e39de09040c8f79aa13cc56baab8db1
base_revision: f1875d570e39de09040c8f79aa13cc56baab8db1

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
1 change: 1 addition & 0 deletions lib/src/drag_select_grid_view/drag_select_grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class DragSelectGridViewState extends State<DragSelectGridView>
final controllerSelectedIndexes = controller.value.selectedIndexes;
if (!setEquals(controllerSelectedIndexes, selectedIndexes)) {
_selectionManager.selectedIndexes = controllerSelectedIndexes;
_updateLocalHistory();
}
}
}
Expand Down
25 changes: 23 additions & 2 deletions test/src/drag_select_grid_view/drag_select_grid_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void main() {
final firstItemFinder = find.byKey(const ValueKey('grid-item-0'));
final lastItemFinder = find.byKey(const ValueKey('grid-item-11'));

Widget widget;
late DragSelectGridViewState dragSelectState;

late Offset mainAxisItemsDistance;
Expand Down Expand Up @@ -64,7 +63,7 @@ void main() {
bool? reverse,
bool? triggerSelectionOnTap,
}) async {
widget = createWidget(
final widget = createWidget(
gridController: gridController,
reverse: reverse,
triggerSelectionOnTap: triggerSelectionOnTap,
Expand Down Expand Up @@ -1014,6 +1013,28 @@ void main() {
},
skip: false,
);

testWidgets(
"Given that the grid has an item selected, "
"when clearing the selection through the controller, "
"then the widget removes the local history entry.",
(tester) async {
final controller = DragSelectGridViewController();
await setUp(tester, gridController: controller);

// Given that the grid has an item selected,
await tester.longPress(firstItemFinder);
await tester.pump();

// when clearing the selection through the controller,
controller.clear();

// then the widget removes the local history entry.
final route = ModalRoute.of(dragSelectState.context);
expect(route!.willHandlePopInternally, isFalse);
},
skip: false,
);
});
});

Expand Down

0 comments on commit e884158

Please sign in to comment.