Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when double tap or long press on Cupertino TextField with ProgressDialog #6

Open
bipinvaylu opened this issue Feb 7, 2021 · 2 comments

Comments

@bipinvaylu
Copy link

I am using this progress dialog library to show progress UI when app is performing something serious IO stuff. But i noticed when we double tap or long press on any Text Input Field, App crashed / shows Red screen in debug.

Here is the related logs:

======== Exception caught by widgets library =======================================================
The following ArgumentError was thrown building _OverlayEntryWidget-[LabeledGlobalKey<_OverlayEntryWidgetState>#235b1](dirty, dependencies: [MediaQuery], state: _OverlayEntryWidgetState#faabb):
Invalid argument(s): 26.0

The relevant error-causing widget was: 
  ProgressDialog file:///Users/bipinvaylu/Documents/Work/Workspaces/xyzapp/lib/main.dart:89:24
When the exception was thrown, this was the stack: 
#0      double.clamp (dart:core-patch/double.dart:183:7)
#1      _CupertinoTextSelectionControls.buildToolbar (package:flutter/src/cupertino/text_selection.dart:478:72)
#2      TextSelectionOverlay._buildToolbar (package:flutter/src/widgets/text_selection.dart:578:34)
#3      _OverlayEntryWidgetState.build (package:flutter/src/widgets/overlay.dart:179:34)
#4      StatefulElement.build (package:flutter/src/widgets/framework.dart:4744:28)
...
====================================================================================================

main.dart - MyApp:

class MyApp extends StatelessWidget {
  MyApp();

  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);

    return Localizations(
      locale: const Locale('en', 'US'),
      delegates: <LocalizationsDelegate<dynamic>>[
        DefaultWidgetsLocalizations.delegate,
        DefaultMaterialLocalizations.delegate,
      ],
      child: MediaQuery(
        data: const MediaQueryData(),
        child: ThemeBuilder(
          defaultThemeMode: ThemeMode.system,
          darkTheme: darkTheme,
          lightTheme: lightTheme,
          statusBarColorBuilder: (theme) => HomePage.tabBackgroundColor,
          themes: getThemes(),
          builder: (context, regularTheme, darkTheme, themeMode) {
            return LayoutBuilder(
                //return LayoutBuilder
                builder: (context, constraints) {
              return OrientationBuilder(
                  //return OrientationBuilder
                  builder: (context, orientation) {
                //initialize SizerUtil()
                SizerUtil().init(constraints, orientation);

                return ProgressDialog(
                  orientation: ProgressOrientation.vertical,
                  loadingText: "Please wait...",
                  backgroundColor: Theme.of(context).backgroundColor,
                  child: MaterialApp(
                    title: "Xyz app",
                    theme: regularTheme,
                    darkTheme: darkTheme,
                    themeMode: themeMode,
                    home: SplashScreen(),
                  ),
                );
              });
            });
          },
        ),
      ),
    );
  }
}

Text input field setup in other screen as follow:

                    Expanded(
                      child: CupertinoTextField(
                        controller: _userNameTextController,
                        keyboardType: TextInputType.name,
                        placeholder: "Friend username",
                        style: Theme.of(context).textTheme.bodyText1,
                        cursorColor: Theme.of(context).primaryColor,
                        prefix: Padding(
                          padding:
                              const EdgeInsets.fromLTRB(9.0, 6.0, 9.0, 6.0),
                          child: Icon(
                            Icons.search,
                            color: Theme.of(context).primaryColor,
                          ),
                        ),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(8.0),
                          color: Theme.of(context).accentColor.withAlpha(70),
                        ),
                      ),
                    ),

I don't see any proper solution as of now. Please help me here to resolve this issue. Else i might need try and switch over to other library and that some extra work. Thanks.

@jnrbo
Copy link

jnrbo commented Mar 2, 2021

The error I was getting was: No MediaQuery widget found

And I solved by moving ProgressDialog outside my main.dart.

main.dart

  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Helpler',
      theme: ThemeData(
        primaryColor: HelplerColors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: SplashScreen(),
    );
  }
  

And In every page I wanted to show progress dialog I did:
(Wrap your app Scaffold Body with progressDialog)

page.dart

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Helpler"),
      ),
      body: ProgressDialog(
        child: Container(
          child: content(),
        ),
      ),
    );
  }

And now is working again!

@bipinvaylu
Copy link
Author

Thanks @jnrbo for your efforts and this solution will help me someday when i use this library again. For now, I switched to another library and which works great for me so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants