|
| 1 | +import 'package:flutter/foundation.dart'; |
1 | 2 | import 'package:flutter/material.dart'; |
2 | 3 | import 'package:flutter_test/flutter_test.dart'; |
3 | 4 | import 'package:scrollview_observer/scrollview_observer.dart'; |
@@ -331,6 +332,61 @@ void main() { |
331 | 332 | await tester.pumpAndSettle(); |
332 | 333 | await tester.pump(observerController.observeIntervalForScrolling); |
333 | 334 | expect(isCalledOnObserve, true); |
| 335 | + |
| 336 | + scrollController.dispose(); |
| 337 | + }); |
| 338 | + |
| 339 | + testWidgets('Check displayingChildModelMap', (tester) async { |
| 340 | + final scrollController = ScrollController(); |
| 341 | + final observerController = GridObserverController( |
| 342 | + controller: scrollController, |
| 343 | + ); |
| 344 | + |
| 345 | + Widget widget = getGridView( |
| 346 | + scrollController: scrollController, |
| 347 | + ); |
| 348 | + GridViewObserveModel? observeResult; |
| 349 | + widget = GridViewObserver( |
| 350 | + child: widget, |
| 351 | + controller: observerController, |
| 352 | + onObserve: (result) { |
| 353 | + observeResult = result; |
| 354 | + }, |
| 355 | + ); |
| 356 | + await tester.pumpWidget(widget); |
| 357 | + await observerController.dispatchOnceObserve( |
| 358 | + isForce: true, |
| 359 | + ); |
| 360 | + expect(observeResult, isNotNull); |
| 361 | + var firstGroupChildList = observeResult?.firstGroupChildList ?? []; |
| 362 | + expect(firstGroupChildList, isNotEmpty); |
| 363 | + expect(firstGroupChildList.first.index, 0); |
| 364 | + expect( |
| 365 | + listEquals( |
| 366 | + observeResult?.displayingChildModelMap.values.toList(), |
| 367 | + observeResult?.displayingChildModelList, |
| 368 | + ), |
| 369 | + true, |
| 370 | + ); |
| 371 | + |
| 372 | + int targetItemIndex = 30; |
| 373 | + observerController.jumpTo( |
| 374 | + index: targetItemIndex, |
| 375 | + alignment: 0, |
| 376 | + ); |
| 377 | + await tester.pumpAndSettle(); |
| 378 | + firstGroupChildList = observeResult?.firstGroupChildList ?? []; |
| 379 | + expect(firstGroupChildList, isNotEmpty); |
| 380 | + expect(firstGroupChildList.first.index, targetItemIndex); |
| 381 | + expect( |
| 382 | + listEquals( |
| 383 | + observeResult?.displayingChildModelMap.values.toList(), |
| 384 | + observeResult?.displayingChildModelList, |
| 385 | + ), |
| 386 | + true, |
| 387 | + ); |
| 388 | + |
| 389 | + scrollController.dispose(); |
334 | 390 | }); |
335 | 391 |
|
336 | 392 | group( |
|
0 commit comments