diff --git a/lib/model/exclude_phone_model.dart b/lib/model/exclude_phone_model.dart index ebea5cc..e783ef2 100644 --- a/lib/model/exclude_phone_model.dart +++ b/lib/model/exclude_phone_model.dart @@ -1,16 +1,19 @@ 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; - final String address; - 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, @@ -20,5 +23,22 @@ class ExcludePhoneModel extends Equatable{ }); @override - List get props => [id,phone,remark,address]; -} \ 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 16e8d94..c7b890f 100644 --- a/lib/model/exclude_phone_model.g.dart +++ b/lib/model/exclude_phone_model.g.dart @@ -6,18 +6,27 @@ part of 'exclude_phone_model.dart'; // JsonSerializableGenerator // ************************************************************************** -ExcludePhoneModel _$ExcludePhoneModelFromJson(Map json) => - ExcludePhoneModel( +ExcludePhoneModel _$ExcludePhoneModelFromJson(Map json) => ExcludePhoneModel( id: json['id'] as int, phone: json['phone'] as String, remark: json['remark'] as String, address: json['address'] as String, ); -Map _$ExcludePhoneModelToJson(ExcludePhoneModel instance) => - { +Map _$ExcludePhoneModelToJson(ExcludePhoneModel instance) => { 'id': instance.id, 'phone': instance.phone, 'remark': instance.remark, '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: "还未选中手机号"); }