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

It works when I try the package normally with a button, but it doesn't work from my own class. #5

Closed
oguz42 opened this issue Apr 5, 2020 · 1 comment

Comments

@oguz42
Copy link

oguz42 commented Apr 5, 2020

Hello, as I mentioned, I checked the package with a button to try it, normally it works fine with the context of that widget, but when I try to run it in my Notification Handler class. I get the message from the top like the usage in this package when it is open. I think the problem is the context in the messaging page and the contex in my class are different so I can't see anything how can I solve this.

My Notification Handler

class NotificationHandler {
  String userId;

  FirebaseMessaging _fcm = FirebaseMessaging();

  static final NotificationHandler _singelton = NotificationHandler._internal();

  factory NotificationHandler() {
    return _singelton;
  }

  NotificationHandler._internal();

  BuildContext myContext;

  initializeFCMNotification(BuildContext context) async {


    myContext = context;

    final _tumKullanicilarViewModel =
    Provider.of<AllUserViewModel>(context, listen: false);
    var initializationSettingsAndroid = AndroidInitializationSettings("yeni");
    var initializatioonSettingsIOS = IOSInitializationSettings(
        onDidReceiveLocalNotification: onDidReceiveLocalNotification);
    var initializationSettings = InitializationSettings(
        initializationSettingsAndroid, initializatioonSettingsIOS);
    flutterLocalNotificationsPlugin.initialize(initializationSettings,
        onSelectNotification: onSelectNotification);
    //_fcm.subscribeToTopic("all");
    // String token= await _fcm.getToken();
    //  print("token : $token");
    _fcm.onTokenRefresh.listen((newToken) async {
      FirebaseUser _currentUser = await FirebaseAuth.instance.currentUser();
      Firestore.instance
          .document("tokens/" + _currentUser.uid)
          .setData({"token": newToken});
    });

    _fcm.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("onmessage ");

        var notificationData = message['notification'];

        //If currently user is there, do not show notification
        var data = message['data'];
        var view;
        if (data != null) {
          view = data['view'];
          print(message['data']);
        }
        print("root gosterirmi //*/0" +
            MyNavigatorObserver.routeStack.toString());

        if (MyNavigatorObserver.routeStack.last == message['data']['view'] &&
            _tumKullanicilarViewModel.tiklaninanUserID ==
                message['data']['gonderenUserID']) {
          print("chat page deyiz");

          //show in app notification 
        } if( _tumKullanicilarViewModel.tiklaninanUserID !=
            message['data']['gonderenUserID']) {
          print("baska birinin sayfasındayım");

         showFlash(
            context: context,
            duration: const Duration(milliseconds: 1500),
            persistent: false,
            builder: (_, controller) {
              return Flash(
                backgroundGradient: RadialGradient(
                  colors: [Colors.red, Colors.white],
                  center: Alignment.topLeft,
                  radius: 2,
                ),
                controller: controller,
                backgroundColor: Colors.white,
                brightness: Brightness.light,
                boxShadows: [BoxShadow(blurRadius: 4)],
                barrierBlur: 2.0,
                barrierColor: Colors.black38,
                barrierDismissible: true,
                style: FlashStyle.floating,
                position: FlashPosition.top,
                child: FlashBar(
                  title: Text('Title'),
                  message: Text('Hello world!'),
                  showProgressIndicator: true,
                  progressIndicatorValueColor:
                  AlwaysStoppedAnimation<Color>(Colors.green),
                  primaryAction: FlatButton(
                    onPressed: () => controller.dismiss(),
                    child: Text('Kapat',
                        style: TextStyle(color: Colors.red, fontSize: 18)),
                  ),
                ),
              );
            },
          );

          

         /* PdyALertDialog(
            baslik: message['data']['title'],
            kapatAlert: "tamam",
            kapatAlertColor: Colors.blue, //89hjb5Qaqg4rYTD48cbjo5kusx2//
            icerik: message['data']['message'],
          ).goster(context);*/
        }

        if (_tumKullanicilarViewModel.tiklaninanUserID ==
            message['data']['gonderenUserID']) {
          print("chat page deyiz ve konustugumuz userdayız");
        } else {
          print("konustugumuz userda değiliiz");
        }
      },
      onLaunch: (Map<String, dynamic> message) async {
        print("onlaunch tetiklendi");
      },
      onResume: (Map<String, dynamic> message) async {
        print("onresume tetiklendi");
      },
      onBackgroundMessage: myBackgroundMessageHandler,
    );
  }}

My Overlay

 Navigator.of(context, rootNavigator: true).push(
          MaterialPageRoute(
            settings:
                RouteSettings(arguments: oankiUser.userID, name: "/chatpage"),
            builder: (context) {
              return ChangeNotifierProvider(
                create: (context) => ChatViewModel(
                  chatUser: oankiUser,
                  currentUser: _userModel.user,
                ),
                child: Overlay(
                  initialEntries: [
                    OverlayEntry(builder: (context) {
                      return KonusmaPage();
                    })
                  ],
                ),
              );
            },
          ),
        );

One more question, in this package, dialogs are shown according to the context value of the page required to do them?

@oguz42
Copy link
Author

oguz42 commented Apr 6, 2020

I solved the problem animation color would accept two different colors in the widget, but did not accept it in a separate class. Giving one color solved the problem.

@oguz42 oguz42 closed this as completed Apr 6, 2020
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

1 participant