flutter_phone 0.0.1 copy "flutter_phone: ^0.0.1" to clipboard
flutter_phone: ^0.0.1 copied to clipboard

outdated

Flutter plugin for phone call,phone logs,phone,audio.

example/lib/main.dart

import 'dart:convert';

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

import 'package:flutter/services.dart';
import 'package:flutter_phone/flutter_phone.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _res = 'Unknown';
  final _flutterPhonePlugin = FlutterPhone();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String? res;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.

    /*
    try {
      res =
          await _flutterPhonePlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      res = 'Failed to get platform version.';
    }
     */

    try {
      //demo
      // res = await _flutterPhonePlugin.getPlatformVersion() ?? 'Unknown platform version';

      //检查权限
      res = await _flutterPhonePlugin.permission() ?? 'Unknown platform version';
      Map permission = jsonDecode(res);
      print("res:permission:"+res);

      //拨号
      if( permission["code"]==200 ){

        // Map map = {"phone":"10000","id":0};
        // res = await _flutterPhonePlugin.toCall(map) ?? 'Unknown result';

        // res = await _flutterPhonePlugin.getSim() ?? 'Unknown result';

        // Map map = {"time": 86400*3*1000 };
        // res = await _flutterPhonePlugin.getCallRecord(map) ?? 'Unknown result';

        Map map = {"time": 86400*3*1000 };
        res = await _flutterPhonePlugin.getCallRecordWithAudio(map) ?? 'Unknown result';

      }
    } on PlatformException {
      res = "{\"code\":200,\"msg\":\"插件抛出异常!\",\"time\":\"0000-00-00 00:00:00\"}";
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _res = res!;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('res: $_res\n'),
        ),
      ),
    );
  }
}
0
likes
0
points
144
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin for phone call,phone logs,phone,audio.

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_phone

Packages that implement flutter_phone