marcglasberg / async_redux

Flutter Package: A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.
Other
230 stars 41 forks source link

'package:flutter/src/widgets/scroll_activity.dart': Failed assertion: line 464 pos 12: 'lastDetails is DragUpdateDetails': is not true. #115

Closed rgr closed 3 years ago

rgr commented 3 years ago

I have a crash on iOS (only) with DropdownButtonFormField and I followed the trace back to the StoreConnector Widget.

It does not happen if the list is short and you don't have to scroll. If your emulator or device has a large screen, you might have to add names to the list so it is forced to scroll...

Here is a simple example it happens with

import 'package:flutter/material.dart';

class DropTest extends StatefulWidget {
  const DropTest({Key? key}) : super(key: key);

  @override
  _DropTestState createState() => _DropTestState();
}

class _DropTestState extends State<DropTest> {
  String name = 'john';

  List<DropdownMenuItem<String>> _buildItems() {
    List options = ['john', 'lisa', 'robert', 'marie', 'jane', 'bruce', 'elton', 'june', 'raph', 'margot'];
    List<DropdownMenuItem<String>> items = [];
    options.forEach((name) {
      items.add(DropdownMenuItem<String>(
        value: name,
        child: Text(name),
      ));
    });

    return items;
  }

  @override
  Widget build(BuildContext context) {
    return DropdownButtonFormField<String>(
      items: _buildItems(),
      onChanged: (value) async {
        setState(() {
          this.name = value!;
          print(this.name);
        });
      },
      value: this.name,
      validator: (value) => value == null ? 'Please fill in your name' : null,
    );
  }
}

So this does not work. It produces the crash...

class MyApp extends StatelessWidget {
    return StoreConnector(
      converter: (Store<AppState> store) => store.state,
      builder: (BuildContext context, AppState state) {

        return GestureDetector(
          onTap: () {
            // Close keyboard on touch anywhere
            FocusManager.instance.primaryFocus?.unfocus();
          },
          child: OverlaySupport(
            child: MaterialApp(
              title: 'xxx,
              theme: AppTheme.theme,
              debugShowCheckedModeBanner: false,
              localizationsDelegates: localizationsDelegates,
              supportedLocales: [
                const Locale('en', 'EN'),
                const Locale('fr', 'FR'),
              ],
              navigatorKey: App.navKey,
              navigatorObservers: [BotToastNavigatorObserver()],
              builder: BotToastInit(),
              initialRoute: state.user.id != 0 ? state.meta.route : '/login',
              onGenerateRoute: RouteManager.generateRoute,
            ),
          ),
        );
      },
    );
  }
}

and when I remove the StoreConnector widget, it does work...

class MyApp extends StatelessWidget {
        return GestureDetector(
          onTap: () {
            // Close keyboard on touch anywhere
            FocusManager.instance.primaryFocus?.unfocus();
          },
          child: OverlaySupport(
            child: MaterialApp(
              title: 'xxx,
              theme: AppTheme.theme,
              debugShowCheckedModeBanner: false,
              localizationsDelegates: localizationsDelegates,
              supportedLocales: [
                const Locale('en', 'EN'),
                const Locale('fr', 'FR'),
              ],
              navigatorKey: App.navKey,
              navigatorObservers: [BotToastNavigatorObserver()],
              builder: BotToastInit(),
              initialRoute: '/login',
              onGenerateRoute: RouteManager.generateRoute,
            ),
          ),
        );
  }
}

So I found the origin but I have no idea why it makes it crash...

Logs ``` async_redux: ^13.0.4 ``` ``` flutter: [2021-09-22 09:33:10.527290 | Catcher | INFO] ---------- ERROR ---------- flutter: [2021-09-22 09:33:10.528323 | Catcher | INFO] 'package:flutter/src/widgets/scroll_activity.dart': Failed assertion: line 464 pos 12: 'lastDetails is DragUpdateDetails': is not true. flutter: [2021-09-22 09:33:10.528883 | Catcher | INFO] flutter: [2021-09-22 09:33:10.530365 | Catcher | INFO] ------- STACK TRACE ------- flutter: [2021-09-22 09:33:10.531266 | Catcher | INFO] #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39) flutter: [2021-09-22 09:33:10.531488 | Catcher | INFO] #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5) flutter: [2021-09-22 09:33:10.531685 | Catcher | INFO] #2 DragScrollActivity.dispatchScrollUpdateNotification package:flutter/…/widgets/scroll_activity.dart:464 flutter: [2021-09-22 09:33:10.531920 | Catcher | INFO] #3 ScrollPosition.didUpdateScrollPositionBy package:flutter/…/widgets/scroll_position.dart:899 flutter: [2021-09-22 09:33:10.532291 | Catcher | INFO] #4 RawScrollbarState._maybeTriggerScrollbar. package:flutter/…/widgets/scrollbar.dart:1243 flutter: [2021-09-22 09:33:10.533119 | Catcher | INFO] #5 SchedulerBinding._invokeFrameCallback package:flutter/…/scheduler/binding.dart:1143 flutter: [2021-09-22 09:33:10.533522 | Catcher | INFO] #6 SchedulerBinding.handleDrawFrame package:flutter/…/scheduler/binding.dart:1088 flutter: [2021-09-22 09:33:10.533638 | Catcher | INFO] #7 SchedulerBinding._handleDrawFrame package:flutter/…/scheduler/binding.dart:996 flutter: [2021-09-22 09:33:10.534724 | Catcher | INFO] #8 _rootRun (dart:async/zone.dart:1428:13) flutter: [2021-09-22 09:33:10.535030 | Catcher | INFO] #9 _CustomZone.run (dart:async/zone.dart:1328:19) flutter: [2021-09-22 09:33:10.535419 | Catcher | INFO] #10 _CustomZone.runGuarded (dart:async/zone.dart:1236:7) flutter: [2021-09-22 09:33:10.535836 | Catcher | INFO] #11 _invoke (dart:ui/hooks.dart:166:10) flutter: [2021-09-22 09:33:10.536175 | Catcher | INFO] #12 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5) flutter: [2021-09-22 09:33:10.536580 | Catcher | INFO] #13 _drawFrame (dart:ui/hooks.dart:129:31) ``` ``` [✓] Flutter (Channel stable, 2.5.1, on macOS 11.5.2 20G95 darwin-arm, locale fr-FR) • Flutter version 2.5.1 at /Users/rgr/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision ffb2ecea52 (4 days ago), 2021-09-17 15:26:33 -0400 • Engine revision b3af521a05 • Dart version 2.14.2 [✗] Android toolchain - develop for Android devices • Android SDK at /Users/rgr/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. [✓] Xcode - develop for iOS and macOS • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.5.1, Build version 12E507 • CocoaPods version 1.11.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions). [✓] VS Code (version 1.60.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.26.0 [✓] Connected device (2 available) • iPhone de Raphaël (mobile) • 555e5664f6e9a581deba0a0f33dd56436e9a4d1a • ios • iOS 14.7.1 18G82 • Chrome (web) • chrome • web-javascript • Google Chrome 93.0.4577.82 ! Doctor found issues in 2 categories. ```
marcglasberg commented 3 years ago

This error has nothing to to with the StoreConnector. The StoreConnector is just a regular StatefulWidget that gets some info from the store.state and passes that info down to another widget.

I suggest you pay attention to the error:

'package:flutter/src/widgets/scroll_activity.dart': Failed assertion: line 464 pos 12: 'lastDetails is DragUpdateDetails': is not true.