Как отправить пользователю уведомление с помощью Flutter, когда пользователь находится в указанной области c? - PullRequest
0 голосов
/ 02 мая 2020

Спасибо, если кто-нибудь может сказать мне, как отправить пользователю уведомление с помощью флаттера, когда пользователь находится в определенной области c. Я хочу, чтобы пользователь автоматически получал уведомление, когда в определенной области c не используется база данных. Как показано ниже, я смог получить уведомление, но хочу отправить уведомление, когда пользователь находится в указанной c области, используя долготу и широту.

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

void main() => runApp(MaterialApp(home: MyApp()));

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

  @override
  void initState() {
    super.initState();
    flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
    var android = AndroidInitializationSettings('icon.jpg');
    var iOS = IOSInitializationSettings();
    var initSetttings = InitializationSettings(android, iOS);
    flutterLocalNotificationsPlugin.initialize(initSetttings,
        onSelectNotification: onSelectNotification);
  }

  Future onSelectNotification(String payload) {
    debugPrint("payload : $payload");
    showDialog(
      context: context,
      builder: (_) => AlertDialog(
        title: Text('supermarket name'),
        content: Text('$payload'),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.redAccent,
        centerTitle: true,
        title: Text('Notifications'),
      ),
      body: Center(
        child: RaisedButton(
          onPressed: showNotification,
          child: Text(
            'Demo',
          ),
        ),
      ),
    );
  }

  showNotification() async {
    var android = AndroidNotificationDetails(
        'CHANNEL NAME', 'channel DESCRIPTION', 'channel id',
        priority: Priority.High,importance: Importance.Max
    );
    var iOS = IOSNotificationDetails();
    var platform = NotificationDetails(android, iOS);
    await flutterLocalNotificationsPlugin.show(
        0, 'supermarket name', 'Promotions available at ........ supermarket outlet', platform,
        payload: 'Promotions available at ........ supermarket outlet');
  }
}
...