phone_call_notifier 1.0.0 copy "phone_call_notifier: ^1.0.0" to clipboard
phone_call_notifier: ^1.0.0 copied to clipboard

PlatformAndroid

Triggers a callback when the phone receives a phone call

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:phone_call_notifier/phone_call_notifier.dart';

void main() {
  runApp(MyApp());
}

class CallRecord {
  final DateTime time;
  final PhoneCallEvent event;

  CallRecord(this.time, this.event);

  factory CallRecord.now(PhoneCallEvent event) {
    return CallRecord(DateTime.now(), event);
  }
}

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

class _MyAppState extends State<MyApp> {
  var calls = <CallRecord>[];

  @override
  void initState() {
    super.initState();

    PhoneCallNotifier().listen.forEach((event) {
      setState(() {
        calls.add(CallRecord.now(event));
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Phone Call Notifier')),
        body: ListView.builder(
          shrinkWrap: true,
          itemCount: calls.length,
          itemBuilder: (context, i) {
            var call = calls[i];
            return ListTile(
              title: Text(call.event.toString()),
              subtitle: Text(call.time.toString()),
            );
          },
        ),
      ),
    );
  }
}
0
likes
120
pub points
35%
popularity

Publisher

unverified uploader

Triggers a callback when the phone receives a phone call

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on phone_call_notifier