From 3f59e7d3f11f20f3bde0be9020cf552769db3d35 Mon Sep 17 00:00:00 2001 From: datang Date: Tue, 13 Sep 2022 17:18:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E9=99=A4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/model/exclude_phone_model.dart | 34 +++++++++++++++++++---- lib/model/exclude_phone_model.g.dart | 15 +++++++++- lib/ui/exclude/exclude_contacts_page.dart | 23 +++++++++++---- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/lib/model/exclude_phone_model.dart b/lib/model/exclude_phone_model.dart index 6658eeb..e783ef2 100644 --- a/lib/model/exclude_phone_model.dart +++ b/lib/model/exclude_phone_model.dart @@ -1,22 +1,44 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:equatable/equatable.dart'; -part 'exclude_phone_model.g.dart'; +part 'exclude_phone_model.g.dart'; @JsonSerializable() -class ExcludePhoneModel extends Equatable{ +class ExcludePhoneModel extends Equatable { final int id; final String phone; final String remark; - factory ExcludePhoneModel.fromJson(Map json) =>_$ExcludePhoneModelFromJson(json); - Map toJson()=> _$ExcludePhoneModelToJson(this); + final String address; + + factory ExcludePhoneModel.fromJson(Map json) => + _$ExcludePhoneModelFromJson(json); + + Map toJson() => _$ExcludePhoneModelToJson(this); const ExcludePhoneModel({ required this.id, required this.phone, required this.remark, + required this.address, }); @override - List get props => [id,phone,remark]; -} \ No newline at end of file + List get props => [id, phone, remark, address]; +} + +@JsonSerializable() +class Exclude extends Equatable { + final String phone; + final String remark; + + factory Exclude.fromJson(Map json) => + _$ExcludeFromJson(json); + Map toJson() => _$ExcludeToJson(this); + @override + List get props => [phone, remark]; + + const Exclude({ + required this.phone, + required this.remark, + }); +} diff --git a/lib/model/exclude_phone_model.g.dart b/lib/model/exclude_phone_model.g.dart index 745bc36..c7b890f 100644 --- a/lib/model/exclude_phone_model.g.dart +++ b/lib/model/exclude_phone_model.g.dart @@ -10,10 +10,23 @@ ExcludePhoneModel _$ExcludePhoneModelFromJson(Map json) => Excl id: json['id'] as int, phone: json['phone'] as String, remark: json['remark'] as String, + address: json['address'] as String, ); Map _$ExcludePhoneModelToJson(ExcludePhoneModel instance) => { 'id': instance.id, 'phone': instance.phone, 'remark': instance.remark, - }; \ No newline at end of file + 'address': instance.address, + }; + + +Exclude _$ExcludeFromJson(Map json) => Exclude( + phone: json['phone'] as String, + remark: json['remark'] as String, +); + +Map _$ExcludeToJson(Exclude instance) => { + 'phone': instance.phone, + 'remark': instance.remark, +}; \ No newline at end of file diff --git a/lib/ui/exclude/exclude_contacts_page.dart b/lib/ui/exclude/exclude_contacts_page.dart index 2f9b778..330ed64 100644 --- a/lib/ui/exclude/exclude_contacts_page.dart +++ b/lib/ui/exclude/exclude_contacts_page.dart @@ -5,6 +5,11 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart'; +import '../../constants/api.dart'; +import '../../model/exclude_phone_model.dart'; +import '../../model/network/api_client.dart'; +import '../../model/network/base_model.dart'; + class ExcludeContactsPage extends StatefulWidget { const ExcludeContactsPage({Key? key}) : super(key: key); @@ -17,7 +22,6 @@ class _ExcludeContactsPageState extends State { List numbers = []; List status = []; var flag = true; - bool _permissionDenied = false; @override void initState() { @@ -83,11 +87,20 @@ class _ExcludeContactsPageState extends State { return ScaffoldThemeWidget( title: "从通讯录添加", bottom: "添加", - onTap: () { + onTap: () async { + List excludeList = []; + for (int i = 0; i < status.length; i++) { + if (status[i] == true) { + excludeList.add( + Exclude(phone: numbers[i], remark: contacts![i].displayName)); + } + } if (status.contains(true)) { - // BotToast.showText(text: "有"); - - Get.back(); + BaseModel res = await apiClient + .request(API.exclude.add, data: {'exclude': excludeList}); + if (res.code == 0) { + Get.back(); + } } else { BotToast.showText(text: "还未选中手机号"); }