import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler_platform_interface/permission_handler_platform_interface.dart'; import 'package:project_telephony/base/base_style.dart'; import 'package:project_telephony/ui/widget/plone_back_button.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:telephony/telephony.dart'; class PrivacyRightsPage extends StatefulWidget { final String name; const PrivacyRightsPage({Key? key, required this.name}) : super(key: key); @override _PrivacyRightsPageState createState() => _PrivacyRightsPageState(); } final Telephony telephony = Telephony.instance; // late final bool permissionsGranted; // String body = ""; // @override // void initState() async { // initPlatformState(); // } class _PrivacyRightsPageState extends State { // final Permission _permission = ; // final PermissionHandlerPlatform _permissionHandler = // PermissionHandlerPlatform.instance; // PermissionStatus _permissionStatus = Permission.phone.request() as PermissionStatus; // PermissionStatus _permissionStatus2 = Permission.sms.request() as PermissionStatus; // Future requestPermission(Permission permission) async { // final status = await _permissionHandler.requestPermissions([permission]); // setState(() { // _permissionStatus = status[permission] ?? PermissionStatus.denied; // }); // } bool sms=false; bool plone=false; @override void initState() { super.initState(); _listenForPermissionStatus(); } Future _listenForPermissionStatus() async { sms=await Permission.sms.request().isGranted; plone =await Permission.phone.request().isGranted; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( elevation: 0, title: Text( widget.name, style: TextStyle( fontSize: BaseStyle.fontSize34, color: BaseStyle.color333333, fontWeight: FontWeight.bold), ), titleSpacing: 162.w, leading: const CloudBackButton(isSpecial: true), backgroundColor: kForeGroundColor), backgroundColor: Colors.white, body: widget.name == "隐私政策" ? null : _getRights(), ); } // Color getPermissionColor() { // if(true){ // return Colors.red; // }else{ // return Colors.green; // } // } // String getPermissionStu() { // if (false) { // return "未允许"; // } else { // return "已允许"; // } // } _getRights(){ return ListTile( onTap: ()async{ // await Permission.phone.request(); // await Permission.sms.request(); // Map statuses = await [ // Permission.sms, // Permission.phone, // ].request(); // // openAppSettings(); print(await Permission.phone.request().isGranted); print(await Permission.sms.request().isGranted); }, title: Text( '获取设备来电', style: Theme.of(context).textTheme.titleMedium, ), subtitle: const Text( "获取设备", ), trailing: Wrap( children: [ Text(sms & plone ?"已允许":"未允许", style: TextStyle(color: sms & plone ?Colors.green:Colors.red)), const Icon(Icons.arrow_forward_ios), ], ), ); } }