Skip to content

Commit b1215e8

Browse files
author
师春雷
committed
update AzListView
1 parent 9608967 commit b1215e8

File tree

4 files changed

+114
-157
lines changed

4 files changed

+114
-157
lines changed

lib/contact/page/contact_list_page.dart

Lines changed: 57 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
33
import 'package:flutter_app/bean/contact.dart';
44
import 'package:flutter_app/contact/page/contact_page.dart';
55
import 'package:flutter_app/contact/ui/contact_list_header.dart';
6-
import 'package:flutter_app/contact/ui/suspension_tag.dart';
6+
import 'package:flutter_app/ui/suspension_tag.dart';
77
import 'package:flutter_app/global/config.dart';
88
import 'package:flutter_app/service/api_service.dart';
99
import 'package:flutter_app/utils/loading_util.dart';
@@ -21,7 +21,7 @@ class _ContactListPageState extends State<ContactListPage> {
2121
List<Contact> _contacts = [];
2222

2323
int _suspensionHeight = 40;
24-
int _itemHeight = 60;
24+
int _itemHeight = 70;
2525

2626
int _themeColorIndex;
2727

@@ -35,65 +35,59 @@ class _ContactListPageState extends State<ContactListPage> {
3535
@override
3636
Widget build(BuildContext context) {
3737
return Scaffold(
38-
appBar: AppBar(
39-
title: Text("通讯录"),
40-
elevation: 0.0,
41-
backgroundColor: themeColors[_themeColorIndex],
42-
centerTitle: true,
43-
),
44-
body: _contacts.isNotEmpty
45-
? AzListView(
46-
data: _contacts,
47-
itemBuilder: (context, model) => _buildListItem(model),
48-
header: AzListViewHeader(
49-
height: 220,
50-
builder: (context) => Diagonal(
51-
axis: Axis.horizontal,
52-
position: DiagonalPosition.BOTTOM_LEFT,
53-
clipHeight: 50.0,
54-
child:
55-
ContactListHeader(name: "SCL", phone: "18601952581"),
56-
),
57-
),
58-
isUseRealIndex: true,
59-
itemHeight: _itemHeight,
60-
suspensionHeight: _suspensionHeight,
61-
indexBarBuilder: (BuildContext context, List<String> tags,
62-
IndexBarTouchCallback onTouch) {
63-
return Container(
64-
margin: EdgeInsets.symmetric(vertical: 16.0, horizontal: 8.0),
65-
decoration: BoxDecoration(
66-
color: Colors.grey[50],
67-
borderRadius: BorderRadius.circular(20.0),
68-
border: Border.all(color: Colors.grey[300], width: .5)),
69-
child: ClipRRect(
70-
borderRadius: BorderRadius.circular(20.0),
71-
child: IndexBar(
72-
data: tags,
73-
itemHeight: 20,
74-
onTouch: (details) {
75-
onTouch(details);
76-
},
77-
),
78-
),
79-
);
80-
},
81-
indexHintBuilder: (context, hint) {
82-
return Container(
83-
alignment: Alignment.center,
84-
width: 60.0,
85-
height: 60.0,
86-
decoration: BoxDecoration(
87-
color: Colors.blue[700].withAlpha(200),
88-
shape: BoxShape.circle,
89-
),
90-
child: Text(hint,
91-
style: TextStyle(color: Colors.white, fontSize: 30.0)),
92-
);
93-
},
94-
)
95-
: getLoadingWidget(),
96-
);
38+
appBar: AppBar(
39+
title: Text("通讯录"),
40+
elevation: 0.0,
41+
backgroundColor: themeColors[_themeColorIndex]),
42+
body: _contacts.isNotEmpty
43+
? AzListView(
44+
data: _contacts,
45+
itemBuilder: (context, model) => _buildListItem(model),
46+
header: AzListViewHeader(
47+
height: 220,
48+
builder: (context) => Diagonal(
49+
axis: Axis.horizontal,
50+
position: DiagonalPosition.BOTTOM_LEFT,
51+
clipHeight: 50.0,
52+
child: ContactListHeader(
53+
name: "SCL", phone: "18601952581"),
54+
),
55+
),
56+
isUseRealIndex: true,
57+
itemHeight: _itemHeight,
58+
suspensionHeight: _suspensionHeight,
59+
indexBarBuilder: (BuildContext context, List<String> tags,
60+
IndexBarTouchCallback onTouch) {
61+
return Container(
62+
margin:
63+
EdgeInsets.symmetric(vertical: 16.0, horizontal: 8.0),
64+
decoration: BoxDecoration(
65+
color: Colors.grey[50],
66+
borderRadius: BorderRadius.circular(20.0),
67+
border:
68+
Border.all(color: Colors.grey[300], width: .5)),
69+
child: ClipRRect(
70+
borderRadius: BorderRadius.circular(20.0),
71+
child: IndexBar(
72+
data: tags,
73+
itemHeight: 20,
74+
onTouch: (details) {
75+
onTouch(details);
76+
})));
77+
},
78+
indexHintBuilder: (context, hint) {
79+
return Container(
80+
alignment: Alignment.center,
81+
width: 60.0,
82+
height: 60.0,
83+
decoration: BoxDecoration(
84+
color: Colors.blue[700].withAlpha(200),
85+
shape: BoxShape.circle),
86+
child: Text(hint,
87+
style: TextStyle(color: Colors.white, fontSize: 30.0)),
88+
);
89+
})
90+
: getLoadingWidget());
9791
}
9892

9993
void getContacts() async {
@@ -107,7 +101,7 @@ class _ContactListPageState extends State<ContactListPage> {
107101
if (contacts == null || contacts.isEmpty) return;
108102
for (int i = 0, length = contacts.length; i < length; i++) {
109103
String pinyin = PinyinHelper.getPinyinE(contacts[i].fullName);
110-
String tag = pinyin.substring(0, 1).toUpperCase();
104+
String tag = pinyin[0].toUpperCase();
111105
if (RegExp("[A-Z]").hasMatch(tag)) {
112106
contacts[i].tagIndex = tag;
113107
} else {
@@ -125,6 +119,7 @@ class _ContactListPageState extends State<ContactListPage> {
125119
offstage: model.isShowSuspension != true,
126120
child: SuspensionTag(susTag: susTag, susHeight: _suspensionHeight)),
127121
SizedBox(
122+
height: _itemHeight.toDouble(),
128123
child: ListTile(
129124
leading: model?.picture?.medium == ""
130125
? CircleAvatar(child: Text(model?.fullName[0]))

lib/contact/ui/suspension_tag.dart

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/ui/suspension_tag.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:flutter/material.dart';
2+
3+
class SuspensionTag extends StatelessWidget {
4+
final String susTag;
5+
final int susHeight;
6+
7+
SuspensionTag({Key key, this.susTag, this.susHeight}) : super(key: key);
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return Container(
12+
padding: EdgeInsets.symmetric(horizontal: 15.0),
13+
height: susHeight.toDouble(),
14+
width: double.infinity,
15+
alignment: Alignment.centerLeft,
16+
color: Color(0xfff3f4f5),
17+
child: Row(children: <Widget>[
18+
Text('$susTag', textScaleFactor: 1.2),
19+
Expanded(child: Divider(height: .0, indent: 10.0))
20+
]));
21+
}
22+
}

lib/weather/page/city_page.dart

Lines changed: 35 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:azlistview/azlistview.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:flutter_app/contact/ui/suspension_tag.dart';
3+
import 'package:flutter_app/ui/suspension_tag.dart';
44
import 'package:flutter_app/service/api_service.dart';
55
import 'package:flutter_app/utils/loading_util.dart';
66
import 'package:flutter_app/utils/route_util.dart';
@@ -18,7 +18,7 @@ class CityPageState extends State<CityPage> {
1818
List<City> _hotCityList = [];
1919

2020
int _suspensionHeight = 40;
21-
int _itemHeight = 50;
21+
int _itemHeight = 58;
2222
String _suspensionTag = "";
2323

2424
@override
@@ -30,48 +30,29 @@ class CityPageState extends State<CityPage> {
3030
@override
3131
Widget build(BuildContext context) {
3232
return Scaffold(
33-
appBar: AppBar(title: Text('城市列表')),
34-
body: Stack(
35-
children: <Widget>[
36-
Offstage(
37-
/// 默认为true,也就是不显示,当为flase的时候,会显示该控件
38-
offstage: _cityList.isNotEmpty,
39-
child: Center(
40-
child: getLoadingWidget(),
41-
),
42-
),
43-
Offstage(
44-
offstage: _cityList.isEmpty,
45-
child: Column(
46-
children: <Widget>[
47-
Container(
48-
alignment: Alignment.centerLeft,
49-
padding: const EdgeInsets.only(left: 15.0),
50-
height: _itemHeight.toDouble(),
51-
child: Text("当前城市: 北京"),
52-
),
53-
Expanded(
54-
child: AzListView(
55-
data: _cityList,
56-
topData: _hotCityList,
57-
itemBuilder: (context, cityBean) =>
58-
_buildCityItems(cityBean),
59-
suspensionWidget: SuspensionTag(
60-
susTag: _suspensionTag,
61-
susHeight: _suspensionHeight,
62-
),
63-
isUseRealIndex: true,
64-
itemHeight: _itemHeight,
65-
suspensionHeight: _suspensionHeight,
66-
onSusTagChanged: _onSusTagChanged,
67-
),
68-
),
69-
],
70-
),
71-
),
72-
],
73-
),
74-
);
33+
appBar: AppBar(title: Text('城市列表')), body: _buildBodyView());
34+
}
35+
36+
Widget _buildBodyView() {
37+
if (_cityList.isEmpty) return getLoadingWidget();
38+
return Column(children: <Widget>[
39+
Container(
40+
alignment: Alignment.centerLeft,
41+
padding: const EdgeInsets.only(left: 15.0),
42+
height: _itemHeight.toDouble(),
43+
child: Text("当前城市: 北京")),
44+
Expanded(
45+
child: AzListView(
46+
data: _cityList,
47+
topData: _hotCityList,
48+
itemBuilder: (context, cityBean) => _buildCityItems(cityBean),
49+
suspensionWidget: SuspensionTag(
50+
susTag: _suspensionTag, susHeight: _suspensionHeight),
51+
isUseRealIndex: true,
52+
itemHeight: _itemHeight,
53+
suspensionHeight: _suspensionHeight,
54+
onSusTagChanged: _onSusTagChanged))
55+
]);
7556
}
7657

7758
void getCityListData() async {
@@ -94,7 +75,7 @@ class CityPageState extends State<CityPage> {
9475
if (list == null || list.isEmpty) return;
9576
for (int i = 0, length = list.length; i < length; i++) {
9677
String pinyin = list[i].namePinyin;
97-
String tag = pinyin.substring(0, 1).toUpperCase();
78+
String tag = pinyin[0].toUpperCase();
9879
list[i].namePinyin = pinyin;
9980
if (RegExp("[A-Z]").hasMatch(tag)) {
10081
list[i].tagIndex = tag;
@@ -111,28 +92,19 @@ class CityPageState extends State<CityPage> {
11192
_buildCityItems(model) {
11293
String susTag = model.getSuspensionTag();
11394
susTag = (susTag == "★" ? "热门城市" : susTag);
114-
return Column(
115-
children: <Widget>[
116-
Offstage(
95+
return Column(children: <Widget>[
96+
Offstage(
11797
offstage: !(model.isShowSuspension == true),
118-
child: SuspensionTag(
119-
susTag: susTag,
120-
susHeight: _suspensionHeight,
121-
),
122-
),
123-
SizedBox(
98+
child: SuspensionTag(susTag: susTag, susHeight: _suspensionHeight)),
99+
SizedBox(
124100
height: _itemHeight.toDouble(),
125101
child: ListTile(
126-
title: Text(
127-
model.parent_city,
128-
),
129-
leading: RoundedLetter.withRandomColors(
130-
model.parent_city.substring(0, 1), 40, 20),
102+
title: Text(model.parent_city),
103+
leading:
104+
RoundedLetter.withRandomColors(model.parent_city[0], 40, 20),
131105
onTap: () =>
132-
pushNewPage(context, WeatherPage(model.parent_city))),
133-
),
134-
],
135-
);
106+
pushNewPage(context, WeatherPage(model.parent_city))))
107+
]);
136108
}
137109

138110
void _onSusTagChanged(String value) {

0 commit comments

Comments
 (0)