contant_page.dart
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:contacts_service/contacts_service.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:intl/intl.dart';
import 'package:one_key/pages/my/contant_left_page.dart';
import 'package:one_key/provider/contant_show_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/widgets/custom_tab_indicator.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:provider/provider.dart';
class ContactListPage extends StatefulWidget {
@override
_ContactListPageState createState() => _ContactListPageState();
}
class _ContactListPageState extends State<ContactListPage> {
List<Contact> _contacts;
List _tabBarTitle;
@override
void initState() {
_tabBarTitle = ['预订联系人', '手机联系人'];
super.initState();
refreshContacts();
}
Future<void> refreshContacts() async {
// Load without thumbnails initially.
var contacts = (await ContactsService.getContacts(
withThumbnails: false, iOSLocalizedLabels: false))
.toList();
// var contacts = (await ContactsService.getContactsForPhone("8554964652"))
// .toList();
setState(() {
_contacts = contacts;
});
// Lazy load thumbnails after rendering initial contacts.
for (final contact in contacts) {
ContactsService.getAvatar(contact).then((avatar) {
if (avatar == null) return; // Don't redraw if no change.
setState(() => contact.avatar = avatar);
});
}
}
void updateContact() async {
Contact ninja = _contacts
.toList()
.firstWhere((contact) => contact.familyName.startsWith("Ninja"));
ninja.avatar = null;
await ContactsService.updateContact(ninja);
refreshContacts();
}
_openContactForm() async {
try {
var contact =
await ContactsService.openContactForm(iOSLocalizedLabels: false);
refreshContacts();
} on FormOperationException catch (e) {
switch (e.errorCode) {
case FormOperationErrorCode.FORM_OPERATION_CANCELED:
case FormOperationErrorCode.FORM_COULD_NOT_BE_OPEN:
case FormOperationErrorCode.FORM_OPERATION_UNKNOWN_ERROR:
default:
print(e.errorCode);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: MyColours.color_ffffff,
appBar: SystemAppBar('联系人'),
body: SafeArea(
child: DefaultTabController(
length: 2,
child: Stack(
children: <Widget>[
TabBarView(
physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ChangeNotifierProvider<ContantShowModel>(
create: (_) => ContantShowModel(),
child: ContantLeftPage()),
Container()
],
),
Positioned(
child: Container(
padding:
EdgeInsets.only(bottom: ScreenUtil().setWidth(10)),
margin: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(30)),
child: TabBar(
indicator: CustomTabIndicator(
radius: 0,
),
indicatorColor: MyColours.color_199095,
indicatorSize: TabBarIndicatorSize.tab,
// indicatorPadding: EdgeInsets.symmetric(
// horizontal: ScreenUtil().setWidth(12)),
labelColor: MyColours.color_199095,
labelStyle: TextStyle(
fontSize: ScreenUtil().setSp(32),
fontWeight: FontWeight.bold),
labelPadding: EdgeInsets.zero,
unselectedLabelStyle:
TextStyle(fontWeight: FontWeight.normal),
unselectedLabelColor: MyColours.color_999999,
tabs: _tabBarTitle.map((value) {
return Tab(
child: Text(value),
);
}).toList()),
))
],
))));
}
}