koukibadr / Elegant-Notification

https://pub.dev/packages/elegant_notification
MIT License
46 stars 30 forks source link

why it is not working in web #99

Open Refaydeen opened 11 months ago

Refaydeen commented 11 months ago

i tried push elegant notification in login screen if response is 400 i need to call notification tried not working

koukibadr commented 11 months ago

@Refaydeen can you provide more details Code snippet and package version used?

Refaydeen commented 10 months ago

i m using this in my Logincontroller but it is not working,if my api is successfull means i need to show the success or else error notification,even though i tried in api method also not working

koukibadr commented 10 months ago

I tested now the package on a web example but it looks like everything okay, can you share more details (code, screen recording)

https://github.com/koukibadr/Elegant-Notification/assets/36043466/6d504d11-89ff-4f70-a957-5a10dcf93d36

reeteshranjan commented 10 months ago

Not working for me too. Saw the example, and not sure what is so different for me. I have a huge codebase and not sure how I could refactor or describe what may be different. There is no error or any other logs when I check the console log.

Refaydeen commented 10 months ago

@reeteshranjan try to use with context of button,use like this ,here i created widget named showSuccessMessage , WidgetsBinding.instance.addPostFrameCallback((_) { showSuccessMessage(context: context,title: 'Success',content: 'Youre Signed in Successfully'); });

reeteshranjan commented 10 months ago

@reeteshranjan try to use with context of button,use like this ,here i created widget named showSuccessMessage , WidgetsBinding.instance.addPostFrameCallback((_) { showSuccessMessage(context: context,title: 'Success',content: 'Youre Signed in Successfully'); });

I don't have a button or any other widget's context available in my flow; only the navigator state context. Will this work?

BenjiFarquhar commented 2 months ago

If I don't add this to my MaterialApp, it just doesn't show the notification:

builder: (context, child) => Overlay(initialEntries: [OverlayEntry(builder: (context) => child!)]),

@koukibadr Do you know why this is the case for me and not the case in the example app?

koukibadr commented 1 month ago

@BenjiFarquhar could you provide flutter doctor output to have an idea about the env you are using

BenjiFarquhar commented 1 month ago

@koukibadr MaterialApp adds an Overlay that can be utilised by this package for global overlay entries. Global overlay entries do not work with MaterialApp.router. See flutter-global-overlay-can-not-be-displayed-with-materialapp-router-when-i-use.

This package has the same code that adds the root Overlay:

    return MaterialApp(
      title: 'Flutter InAppNotifications',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter InAppNotifications'),
      builder: InAppNotifications.init(),
    );

this is that init function:

  static TransitionBuilder init({
    TransitionBuilder? builder,
  }) {
    return (BuildContext context, Widget? child) {
      if (builder != null) {
        return builder(context, InAppNotificationsOverlay(child: child));
      } else {
        return InAppNotificationsOverlay(child: child);
      }
    };
  }

Given this limitation of MaterialApp.router, which is very popular now for Navigation 2.0, I believe this package will need to mention my solution above (in my first comment) or incorporate it into the package. It is quite likely that this original issue is caused by this.

[✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale en-GB) • Flutter version 3.22.1 on channel stable at /Users/benjaminfarquhar/fvm/versions/3.22.1 • Upstream repository https://github.com/flutter/flutter.git • Framework revision a14f74ff3a (9 weeks ago), 2024-05-22 11:08:21 -0500 • Engine revision 55eae6864b • Dart version 3.4.1 • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/benjaminfarquhar/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/benjaminfarquhar/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11609105)

[✓] IntelliJ IDEA Community Edition (version 2023.2.2) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.91.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.92.0

[✓] Connected device (6 available) • Benji’s iPhone 13 mini (mobile) • 00008110-001119123C7B801E • ios • iOS 17.5.1 21F90 • iPhone 15 Pro (mobile) • 71C2F283-7754-4947-83DB-338111A5D7E8 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator) • iPad Pro 11-inch (M4) (mobile) • C92E0632-6BE7-42C1-BB93-64D89EB44476 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.183

[✓] Network resources • All expected network resources are available.

• No issues found!