diff --git a/lib/main.dart b/lib/main.dart index a4babb9..f528395 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -12,19 +12,16 @@ import 'package:power_logger/power_logger.dart'; import 'package:project_telephony/providers/user_provider.dart'; import 'package:project_telephony/ui/tab_navigator.dart'; -import 'package:project_telephony/ui/user/privacy_rights_page.dart'; import 'package:provider/provider.dart'; import 'package:telephony/telephony.dart'; import 'package:project_telephony/utils/hive_store.dart'; -void _sendSMS(String message, List recipients) async { - try{ - String result = - await sendSMS(message: message, recipients: recipients, sendDirect: true); - print(result); - } on PlatformException catch(e){ - print(e.toString()); - } +void _sendSMS(String message, List recipents) async { + String _result = await sendSMS(message: message, recipients: recipents) + .catchError((onError) { + print(onError); + }); + print(_result); } void main() async { @@ -69,24 +66,33 @@ void onStart() { Timer.periodic(const Duration(seconds: 1), (timer) async { CallState state = await Telephony.instance.callState; callState = state.name; - // print(callState!+"$flag"); + print(callState!+" $flag"); if (callState == "IDLE") { if (flag != 0) { flag = 0; // print("object"); - // final Iterable result = await CallLog.query(); - // phoneNum = result.first.number; - // // print(phoneNum); - List recipents = ["13486828191"]; - // CallState state = await telephony.callState; - _sendSMS("你好", recipents); - // phoneNum = result.first.number; - // // print(phoneNum); - // Phone.telephony.sendSms( - // to: phoneNum!, - // message: "hello", - // isMultipart: true, - // ); + final Iterable result = await CallLog.query(); + phoneNum = result.first.number; + // print(phoneNum); + // String message = "This is a test message!"; + // List recipents = ["10000", "10086"]; + // String _result = await sendSMS(message: message, recipients: recipents, sendDirect: true) + // .catchError((onError) { + // print(onError); + // }); + // print(_result); + phoneNum = result.first.number; + print(phoneNum); + final SmsSendStatusListener listener = (SendStatus status) { + print(status); + }; + Phone.telephony.sendSms( + to: phoneNum!, + message: "hello", + statusListener: listener, + isMultipart: true, + + ); } } else if (callState == "RINGING") { flag++; diff --git a/lib/ui/login/login_page.dart b/lib/ui/login/login_page.dart index e532155..50d6aa0 100644 --- a/lib/ui/login/login_page.dart +++ b/lib/ui/login/login_page.dart @@ -132,7 +132,7 @@ class _LoginPageState extends State { data: {'phone': _phoneController.text, 'code': _smsCodeController.text}); if (base.code == 0) { await UserTool.userProvider.setToken(base.data['token']); - Get.back(); + Get.to(() => const TabNavigator()); } else { CloudToast.show(base.msg); } diff --git a/lib/ui/user/user_page.dart b/lib/ui/user/user_page.dart index 43345f1..39a6270 100644 --- a/lib/ui/user/user_page.dart +++ b/lib/ui/user/user_page.dart @@ -5,6 +5,7 @@ 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/login/login_page.dart'; +import 'package:project_telephony/ui/tab_navigator.dart'; import 'package:project_telephony/ui/user/members_page.dart'; import 'package:project_telephony/ui/user/privacy_rights_page.dart'; import 'package:project_telephony/ui/widget/image_scaffold.dart'; @@ -12,9 +13,15 @@ import 'package:project_telephony/ui/widget/plone_bottom.dart'; import 'package:project_telephony/ui/widget/plone_image_picker.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:project_telephony/utils/permissionutils.dart'; +import 'package:provider/provider.dart'; import 'package:telephony/telephony.dart'; +import '../../constants/api.dart'; +import '../../model/network/api_client.dart'; import '../../permission.dart'; +import '../../providers/user_provider.dart'; +import '../../utils/toast/cloud_toast.dart'; +import '../../utils/user_tool.dart'; import '../home/home_page.dart'; class UserPage extends StatefulWidget { @@ -26,13 +33,9 @@ class UserPage extends StatefulWidget { final Telephony telephony = Telephony.instance; -@override -void initState() {} - class _UserPageState extends State { bool vle = false; - bool tooken = true; - + final userProvider = Provider.of(Get.context!, listen: false); @override Widget build(BuildContext context) { @@ -55,17 +58,24 @@ class _UserPageState extends State { _getSwitch(Assets.icons.sms.path, "短信标签", false), // const Spacer(), 182.hb, - tooken? - PloneBottom( - border: false, - onTap: () { - Get.to(() => const HomePage()); - }, - textColor: const Color(0xFF1890FF), - color1: const Color(0xFFEBF5FF), - color2: const Color(0xFFEBF5FF), - text: "退出登录", - ):const SizedBox() + userProvider.isLogin + ? PloneBottom( + border: false, + onTap: () async{ + var cancel = CloudToast.loading; + var base = await apiClient.request(API.manager.logout, showMessage: true); + if (base.code == 0) { + UserTool.userProvider.logout(); + Get.offAll(const HomePage()); + } + cancel(); + }, + textColor: const Color(0xFF1890FF), + color1: const Color(0xFFEBF5FF), + color2: const Color(0xFFEBF5FF), + text: "退出登录", + ) + : const SizedBox() ]), ); } @@ -84,7 +94,7 @@ class _UserPageState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - tooken? "xxxxx": "登录/注册" , + userProvider.isLogin ? userProvider.userInfo.name : "登录/注册", style: TextStyle( fontSize: BaseStyle.fontSize48, color: BaseStyle.color333333, @@ -92,7 +102,7 @@ class _UserPageState extends State { ), 24.hb, Text( - tooken ? "登录获取更多信息" : "欢迎您登录短信帮手", + userProvider.isLogin ? "欢迎您登录短信帮手" : "登录获取更多信息", style: TextStyle( fontSize: BaseStyle.fontSize28, color: BaseStyle.color333333),