JackJonson / flutter_styled_toast

A Styled Toast Flutter package.
Apache License 2.0
76 stars 43 forks source link

Without giving context getting error. But context is optional param. #21

Closed saravananmnm closed 3 years ago

saravananmnm commented 3 years ago

======== Exception caught by gesture =============================================================== The following assertion was thrown while handling a gesture: 'package:flutter_styled_toast/src/styled_toast.dart': Failed assertion: line 73 pos 10: 'context != null': is not true.

JackJonson commented 3 years ago

@saravananmnm Can you provide flutter doctor -v and elaborate on what exactly are you trying to achieve along with expected vs actual behavior ? Thanks.

saravananmnm commented 3 years ago

C:\Saravanan\Flutter_sdk\flutter\bin\flutter.bat doctor --verbose [√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.19042.1165], locale en-US) • Flutter version 1.22.5 at C:\Saravanan\Flutter_sdk\flutter • Framework revision 7891006299 (9 months ago), 2020-12-10 11:54:40 -0800 • Engine revision ae90085a84 • Dart version 2.10.4

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at C:\Users\WDSI\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.3 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted.

[!] Android Studio (version 4.1.0) • Android Studio at C:\Program Files\Android\Android Studio X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] Connected device (1 available) • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)

! Doctor found issues in 1 category.

saravananmnm commented 3 years ago

@JackJonson Yes. I expect without context is getting errors. But in default constructor doesn't have the required field of context.

JackJonson commented 3 years ago

@saravananmnm Hi, There is a solution: If you want to show toast without giving context, must wrap your app with StyledToast.

Simple global configuration, wrap you app with StyledToast.


StyledToast(
  locale: const Locale('en', 'US'),
  child: MaterialApp(
            title: appTitle,
            showPerformanceOverlay: showPerformance,
            home: LayoutBuilder(
              builder: (BuildContext context, BoxConstraints constraints) {
                return MyHomePage(
                  title: appTitle,
                  onSetting: onSettingCallback,
                );
              },
            ),
          ),
)
saravananmnm commented 3 years ago

@JackJonson Thanks for the simple solution.