huhuang03/reorderable_grid_view

Expected a value of type 'RenderBox', but got one of type 'Null'

Closed this issue · 5 comments

i think the issue is that am using a column and a flexible inside so whenever i start a dragging action it gives me the following Error:

Error: Expected a value of type 'RenderBox', but got one of type 'Null' at Object.throw_ [as throw] (http://localhost:59837/dart_sdk.js:5061:11) at Object.castError (http://localhost:59837/dart_sdk.js:5020:15) at Object.cast [as as] (http://localhost:59837/dart_sdk.js:5345:17) at Function.as_C [as as] (http://localhost:59837/dart_sdk.js:4966:19) at reorderable_wrapper_widget.ReorderableWrapperWidgetState.new.getPos (http://localhost:59837/packages/reorderable_grid_view/src/sliver_grid_with_reorderable_pos_delegate.dart.lib.js:1036:34) at reorderable_wrapper_widget.ReorderableWrapperWidgetState.new.getOffsetInDrag (http://localhost:59837/packages/reorderable_grid_view/src/sliver_grid_with_reorderable_pos_delegate.dart.lib.js:1080:25) at reorderable_item.ReorderableItemViewState.new.updateForGap (http://localhost:59837/packages/reorderable_grid_view/src/sliver_grid_with_reorderable_pos_delegate.dart.lib.js:849:40) at reorderable_wrapper_widget.ReorderableWrapperWidgetState.new.updateDragTarget (http://localhost:59837/packages/reorderable_grid_view/src/sliver_grid_with_reorderable_pos_delegate.dart.lib.js:1166:20) at updateDragTarget.next (<anonymous>) at runBody (http://localhost:59837/dart_sdk.js:38659:34) at Object._async [as async] (http://localhost:59837/dart_sdk.js:38690:7) at reorderable_wrapper_widget.ReorderableWrapperWidgetState.new.updateDragTarget (http://localhost:59837/packages/reorderable_grid_view/src/sliver_grid_with_reorderable_pos_delegate.dart.lib.js:1161:22) at reorderable_wrapper_widget.ReorderableWrapperWidgetState.new.[_onDragUpdate] (http://localhost:59837/packages/reorderable_grid_view/src/sliver_grid_with_reorderable_pos_delegate.dart.lib.js:1096:14) at drag_info.DragInfo.new.update (http://localhost:59837/packages/reorderable_grid_view/src/sliver_grid_with_reorderable_pos_delegate.dart.lib.js:563:27) at multidrag._DelayedPointerState.new.[_move] (http://localhost:59837/packages/flutter/src/gestures/multidrag.dart.lib.js:92:39) at multidrag.DelayedMultiDragGestureRecognizer.new.[_handleEvent] (http://localhost:59837/packages/flutter/src/gestures/multidrag.dart.lib.js:228:21) at pointer_router.PointerRouter.new.[_dispatch] (http://localhost:59837/packages/flutter/src/gestures/pointer_router.dart.lib.js:85:9) at http://localhost:59837/packages/flutter/src/gestures/pointer_router.dart.lib.js:115:26 at LinkedMap.new.forEach (http://localhost:59837/dart_sdk.js:26433:11) at pointer_router.PointerRouter.new.[_dispatchEventToRoutes] (http://localhost:59837/packages/flutter/src/gestures/pointer_router.dart.lib.js:113:29) at pointer_router.PointerRouter.new.route (http://localhost:59837/packages/flutter/src/gestures/pointer_router.dart.lib.js:108:37) at binding$5.WidgetsFlutterBinding.new.handleEvent (http://localhost:59837/packages/flutter/src/gestures/binding.dart.lib.js:362:26) at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:59837/packages/flutter/src/gestures/binding.dart.lib.js:347:24) at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:59837/packages/flutter/src/rendering/layer.dart.lib.js:5118:13) at binding$5.WidgetsFlutterBinding.new.[_handlePointerEventImmediately] (http://localhost:59837/packages/flutter/src/gestures/binding.dart.lib.js:321:14) at binding$5.WidgetsFlutterBinding.new.handlePointerEvent (http://localhost:59837/packages/flutter/src/gestures/binding.dart.lib.js:295:43) at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (http://localhost:59837/packages/flutter/src/gestures/binding.dart.lib.js:285:14) at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (http://localhost:59837/packages/flutter/src/gestures/binding.dart.lib.js:276:54) at Object.invoke1 (http://localhost:59837/dart_sdk.js:179667:7) at _engine.EnginePlatformDispatcher.__.invokeOnPointerDataPacket (http://localhost:59837/dart_sdk.js:160119:15) at _engine.PointerBinding.__.[_onPointerData] (http://localhost:59837/dart_sdk.js:160965:49) at http://localhost:59837/dart_sdk.js:161373:26 at http://localhost:59837/dart_sdk.js:161340:16 at loggedHandler (http://localhost:59837/dart_sdk.js:161058:11)
Sample code with the problem

@OverRide
Widget build(BuildContext context) {
///
///Builds a single tile widget
Widget buildTile(HomePageTile tile) {
return GestureDetector(
key: ValueKey(tile.id),
onTap: () => navigateFromTiles(tile.id, context),
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: tile.backgroundColor,
shape: BoxShape.rectangle,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
flex: 2,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
tile.tileIcon,
size: 40,
color: Colors.grey[800],
),
],
),
),
Text(
tile.name,
style: Theme.of(context).textTheme.subtitle1!.copyWith(
color: Colors.grey[800], fontWeight: FontWeight.bold),
),
]),
),
);
}

/// when the reorder completes remove the list entry from its old position
/// and insert it at its new index
void _onReorder(int oldIndex, int newIndex) {
  setState(() {
    final item = widget.features.removeAt(oldIndex);
    widget.features.insert(newIndex, item);
  });
}
return ReorderableGridView.count(
  padding: const EdgeInsets.all(10),
  childAspectRatio: 1.7,
  crossAxisSpacing: 10,
  mainAxisSpacing: 10,
  crossAxisCount: 2,
  children: List.generate(widget.features.length,
          (index) => buildTile(widget.features[index])),
  onReorder: _onReorder,
  footer: [buildTile(addTile)],
);

}
}

I have check your example . And can't reproduce.

In the log it seems some error in lib code. Can you try 2.2.1 version?

huyhb commented

i have a same issues? i dont know problem.

Can you try the latest version:

dependencies:
  reorderable_grid_view: ^2.2.1

If still have the issue, can you paste the log.

使用 ReorderableSliverGridView.count,在移动最后一个项目的时候,会报下面这个错,移动其它的项目都是正常的,不报错。

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: type 'Null' is not a subtype of type 'RenderBox' in type cast
#0 ReorderableGridStateMixin.getPos (package:reorderable_grid_view/src/reorderable_grid_mixin.dart:69:55)
#1 ReorderableGridStateMixin.getOffsetInDrag (package:reorderable_grid_view/src/reorderable_grid_mixin.dart:143:16)
#2 ReorderableItemViewState.updateForGap (package:reorderable_grid_view/src/reorderable_item.dart:68:35)
#3 ReorderableGridStateMixin.updateDragTarget (package:reorderable_grid_view/src/reorderable_grid_mixin.dart:263:14)
#4 ReorderableGridStateMixin._onDragUpdate (package:reorderable_grid_view/src/reorderable_grid_mixin.dart:178:5)
#5 DragInfo.update (package:reorderable_grid_view/src/drag_info.dart:121:15)
#6 MultiDragPointerState._move
package:flutter/…/gestures/multidrag.dart:86
#7 MultiDragGestureRecognizer._handleEvent
package:flutter/…/gestures/multidrag.dart:259
#8 PointerRouter._dispatch (package:flut<…>

感谢指出问题,请使用2.2.2版本,我测试已经修复了。(Thanks for pointer this. Please use version 2.2.2, myself test is ok).

dependencies:
  reorderable_grid_view: ^2.2.2