# Conflicts:
#	lib/ui/user/user_page.dart
dyb
戴余标 2 years ago
commit 19e7b95ffe

@ -3,5 +3,6 @@
<!-- Flutter needs it to communicate with the running application <!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc. to allow setting breakpoints, to provide hot reload, etc.
--> -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
</manifest> </manifest>

@ -11,82 +11,82 @@ import 'package:project_telephony/permission.dart';
import 'package:project_telephony/ui/login/login_page.dart'; import 'package:project_telephony/ui/login/login_page.dart';
import 'package:project_telephony/ui/tab_navigator.dart'; import 'package:project_telephony/ui/tab_navigator.dart';
import 'package:telephony/telephony.dart'; // import 'package:telephony/telephony.dart';
onBackgroundMessage(SmsMessage message) { // onBackgroundMessage(SmsMessage message) {
debugPrint("onBackgroundMessage called"); // debugPrint("onBackgroundMessage called");
} // }
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await initializeService(); // await initializeService();
runApp(const MyApp()); runApp(const MyApp());
// SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle( // SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
// statusBarColor: Colors.transparent, // // statusBarColor: Colors.transparent, //
// statusBarIconBrightness: Brightness.dark); // // statusBarIconBrightness: Brightness.dark); //
} }
Future<void> initializeService() async { // Future<void> initializeService() async {
final service = FlutterBackgroundService(); // final service = FlutterBackgroundService();
service.setNotificationInfo(title: '短信助手', content: '正在后台运行'); // service.setNotificationInfo(title: '短信助手', content: '正在后台运行');
await service.configure( // await service.configure(
androidConfiguration: AndroidConfiguration( // androidConfiguration: AndroidConfiguration(
onStart: onStart, // onStart: onStart,
autoStart: true, // autoStart: true,
isForegroundMode: true, // isForegroundMode: true,
), // ),
iosConfiguration: IosConfiguration( // iosConfiguration: IosConfiguration(
autoStart: true, // autoStart: true,
onForeground: onStart, // onForeground: onStart,
onBackground: onIosBackground, // onBackground: onIosBackground,
), // ),
); // );
} // }
void onIosBackground() { void onIosBackground() {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
// print('FLUTTER BACKGROUND FETCH'); // print('FLUTTER BACKGROUND FETCH');
} }
void onStart() { // void onStart() {
int flag = 0; // int flag = 0;
String? phoneNum, callState; // String? phoneNum, callState;
WidgetsFlutterBinding.ensureInitialized(); // WidgetsFlutterBinding.ensureInitialized();
//
Timer.periodic(const Duration(seconds: 1), (timer) async { // Timer.periodic(const Duration(seconds: 1), (timer) async {
CallState state = await Telephony.instance.callState; // CallState state = await Telephony.instance.callState;
callState = state.name; // callState = state.name;
// print(callState!+"$flag"); // // print(callState!+"$flag");
if (callState == "IDLE") { // if (callState == "IDLE") {
if (flag != 0) { // if (flag != 0) {
flag = 0; // flag = 0;
final Iterable<CallLogEntry> result = await CallLog.query(); // final Iterable<CallLogEntry> result = await CallLog.query();
phoneNum = result.first.number; // phoneNum = result.first.number;
print(phoneNum); // print(phoneNum);
Phone.telephony.sendSms( // Phone.telephony.sendSms(
to: phoneNum!, // to: phoneNum!,
message: "hello", // message: "hello",
isMultipart: true, // isMultipart: true,
); // );
phoneNum = result.first.number; // phoneNum = result.first.number;
// print(phoneNum); // // print(phoneNum);
Phone.telephony.sendSms( // Phone.telephony.sendSms(
to: phoneNum!, // to: phoneNum!,
message: "hello", // message: "hello",
isMultipart: true, // isMultipart: true,
); // );
} // }
} else if (callState == "RINGING") { // } else if (callState == "RINGING") {
flag++; // flag++;
} else if (callState == "OFFHOOK") { // } else if (callState == "OFFHOOK") {
flag++; // flag++;
} // }
}); // });
} // }
class Phone { // class Phone {
static Telephony telephony = Telephony.instance; // static Telephony telephony = Telephony.instance;
} // }
class MyApp extends StatefulWidget { class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key); const MyApp({Key? key}) : super(key: key);
@ -124,26 +124,26 @@ class _MyAppState extends State<MyApp> {
// }); // });
} }
onMessage(SmsMessage message) async { // onMessage(SmsMessage message) async {
setState(() { // setState(() {
_message = message.body ?? "Error reading message body."; // _message = message.body ?? "Error reading message body.";
}); // });
} // }
onSendStatus(SendStatus status) { // onSendStatus(SendStatus status) {
setState(() { // setState(() {
_message = status == SendStatus.SENT ? "sent" : "delivered"; // _message = status == SendStatus.SENT ? "sent" : "delivered";
}); // });
} // }
Future<void> initPlatformState() async { // Future<void> initPlatformState() async {
final bool? result = await Phone.telephony.requestPhoneAndSmsPermissions; // final bool? result = await Phone.telephony.requestPhoneAndSmsPermissions;
if (result != null && result) { // if (result != null && result) {
Phone.telephony.listenIncomingSms( // Phone.telephony.listenIncomingSms(
onNewMessage: onMessage, onBackgroundMessage: onBackgroundMessage); // onNewMessage: onMessage, onBackgroundMessage: onBackgroundMessage);
} // }
if (!mounted) return; // if (!mounted) return;
} // }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

@ -1,70 +1,69 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.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/base/base_style.dart';
// import 'package:project_telephony/main.dart';
import 'package:project_telephony/ui/widget/plone_back_button.dart'; import 'package:project_telephony/ui/widget/plone_back_button.dart';
import 'package:project_telephony/ui/widget/plone_bottom.dart';
import 'package:project_telephony/utils/headers.dart'; import 'package:project_telephony/utils/headers.dart';
import 'package:telephony/telephony.dart'; // import 'package:telephony/telephony.dart';
class PrivacyRightsPage extends StatefulWidget { class PrivacyRightsPage extends StatefulWidget {
final String name; final String name;
const PrivacyRightsPage({Key? key, required this.name}) : super(key: key); const PrivacyRightsPage({Key? key, required this.name}) : super(key: key);
@override @override
_PrivacyRightsPageState createState() => _PrivacyRightsPageState(); _PrivacyRightsPageState createState() => _PrivacyRightsPageState();
} }
final Telephony telephony = Telephony.instance; // final Telephony telephony = Telephony.instance;
// late final bool permissionsGranted; // late final bool permissionsGranted;
// String body = ""; // String body = "";
// @override // @override
// void initState() async { // initState() async {
// initPlatformState();
// // initPlatformState();
// } // }
bool? pd;
class _PrivacyRightsPageState extends State<PrivacyRightsPage> { class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
final Permission _permission = Permission.phone;
final PermissionHandlerPlatform _permissionHandler =
PermissionHandlerPlatform.instance;
PermissionStatus _permissionStatus = PermissionStatus.denied;
Future<void> requestPermission(Permission permission) async {
final status = await _permissionHandler.requestPermissions([permission]);
setState(() {
_permissionStatus = status[permission] ?? PermissionStatus.denied;
});
}
@override @override
void initState() { void initState() {
Future.delayed(const Duration(seconds: 2), () async {
await _refresh();
});
setState(() {});
super.initState(); super.initState();
_listenForPermissionStatus();
} }
void _listenForPermissionStatus() async { _refresh() async {
final status = await _permissionHandler.checkPermissionStatus(_permission); var status = await Permission.camera.status;
setState(() => _permissionStatus = status); pd = status.isDenied;
setState(() {});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
elevation: 0, elevation: 0,
title: Text( title: Text(
widget.name, widget.name,
style: TextStyle( style: TextStyle(
fontSize: BaseStyle.fontSize34, fontSize: BaseStyle.fontSize34,
color: BaseStyle.color333333, color: BaseStyle.color333333,
fontWeight: FontWeight.bold), fontWeight: FontWeight.bold),
), ),
titleSpacing: 162.w, titleSpacing: 162.w,
leading: const CloudBackButton(isSpecial: true), leading: const CloudBackButton(isSpecial: true),
backgroundColor: kForeGroundColor), backgroundColor: kForeGroundColor),
backgroundColor: Colors.white, backgroundColor: Colors.white,
body: widget.name == "隐私政策" ? null : _getRights(true), body: widget.name == "隐私政策"
); ? null
: Column(
children: [
_getRights(pd!),
],
));
} }
// onMessage(SmsMessage message) async { // onMessage(SmsMessage message) async {
@ -92,116 +91,68 @@ class _PrivacyRightsPageState extends State<PrivacyRightsPage> {
// } // }
_getRights(bool pd) { _getRights(bool pd) {
return ListView( return GestureDetector(
children: Permission.values onTap: () {},
.where((permission) { child: Container(
return permission == Permission.phone || height: 144.w,
permission == Permission.sms; width: 750.w,
}) padding: EdgeInsets.symmetric(horizontal: 64.w, vertical: 17.w),
.map((permission) => PermissionWidget(permission)) child: Row(
.toList()); crossAxisAlignment: CrossAxisAlignment.center,
} children: [
} Column(
crossAxisAlignment: CrossAxisAlignment.start,
class PermissionWidget extends StatefulWidget { children: [
const PermissionWidget(this._permission); Text(
'获取设备来电',
final Permission _permission; style: TextStyle(
fontSize: 32.sp,
@override color: BaseStyle.color333333,
_PermissionState createState() => _PermissionState(_permission); fontWeight: FontWeight.bold),
} ),
16.hb,
class _PermissionState extends State<PermissionWidget> { Text('用于获取设备',
_PermissionState(this._permission); style: TextStyle(
fontSize: 28.sp, color: BaseStyle.color999999)),
final Permission _permission; ],
final PermissionHandlerPlatform _permissionHandler = ),
PermissionHandlerPlatform.instance; 269.wb,
PermissionStatus _permissionStatus = PermissionStatus.denied; Text(pd ? "未允许" : "已允许",
List<String> title = [ style: TextStyle(
"获取来电权限", fontSize: 24.sp,
"获取短信权限", color: pd
]; ? const Color(0xFFFF4D4D)
List<String> sub = [ : BaseStyle.color999999)),
"用于监听来电状态", SizedBox(
"用于发送短信", width: 48.w,
]; height: 48.w,
child: const Icon(
@override Icons.keyboard_arrow_right,
void initState() { ),
super.initState(); ),
],
_listenForPermissionStatus(); )),
} );
void _listenForPermissionStatus() async {
final status = await _permissionHandler.checkPermissionStatus(_permission);
setState(() => _permissionStatus = status);
}
Color getPermissionColor() {
switch (_permissionStatus) {
case PermissionStatus.denied:
return Colors.red;
case PermissionStatus.granted:
return Colors.green;
case PermissionStatus.limited:
return Colors.orange;
default:
return Colors.grey;
}
}
String getPermissionStu() {
switch (_permissionStatus) {
case PermissionStatus.denied:
return "未允许";
case PermissionStatus.granted:
return "已允许";
default:
return "未允许";
}
} }
@override _getA() {
Widget build(BuildContext context) { return PloneBottom(
return ListTile( onTap: () async {
title: Text( var status = await Permission.camera.status;
_permission.value==8?title[0]:title[1], if (status.isDenied) {
style: Theme.of(context).textTheme.titleMedium, // openAppSettings();//
), // print(status.isDenied);
subtitle: Text( // print("已允许");
_permission.value==8?sub[0]:sub[1], } else {
), print("未允许");
trailing: Wrap( }
children: [
Text(getPermissionStu(),
style: TextStyle(color: getPermissionColor())),
const Icon(Icons.arrow_forward_ios),
],
),
onTap: () {
requestPermission(_permission);
}, },
); );
} // var status = await Permission.camera.status;
// if (status.isDenied) {
void checkServiceStatus( // return Text("已允许");
BuildContext context, PermissionWithService permission) async { // } else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( // return Text("未允许");
content: Text( // }
(await _permissionHandler.checkServiceStatus(permission)).toString()),
));
}
Future<void> requestPermission(Permission permission) async {
final status = await _permissionHandler.requestPermissions([permission]);
setState(() {
print(status);
_permissionStatus = status[permission] ?? PermissionStatus.denied;
print(_permissionStatus);
});
} }
} }

@ -33,6 +33,7 @@ class _UserPageState extends State<UserPage> {
bool vle = false; bool vle = false;
bool tooken = true; bool tooken = true;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CloudScaffold( return CloudScaffold(

@ -875,6 +875,8 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.0+2" version: "3.0.0+2"
<<<<<<< HEAD
=======
telephony: telephony:
dependency: "direct main" dependency: "direct main"
description: description:
@ -882,6 +884,7 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.0" version: "0.2.0"
>>>>>>> b3fc551780d9788cb9ec28a234cb871209f9f7ce
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
@ -996,4 +999,8 @@ packages:
version: "3.1.1" version: "3.1.1"
sdks: sdks:
dart: ">=2.17.0-0 <3.0.0" dart: ">=2.17.0-0 <3.0.0"
<<<<<<< HEAD
flutter: ">=2.8.1"
=======
flutter: ">=2.8.0" flutter: ">=2.8.0"
>>>>>>> b3fc551780d9788cb9ec28a234cb871209f9f7ce

@ -84,6 +84,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your # activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint # package. See that file for information about deactivating specific lint
# rules and activating additional ones. # rules and activating additional ones.
# test: ^1.21.4
flutter_lints: ^1.0.0 flutter_lints: ^1.0.0
#model自动生成 #model自动生成
json_serializable: ^6.1.3 json_serializable: ^6.1.3

@ -7,6 +7,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
// import 'package:test/test.dart';
import 'package:project_telephony/main.dart'; import 'package:project_telephony/main.dart';

Loading…
Cancel
Save