Skip to content

Commit aa2f904

Browse files
committed
修改自定义Index_bar属性
1 parent fa7735d commit aa2f904

File tree

3 files changed

+144
-79
lines changed

3 files changed

+144
-79
lines changed

ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ DEPENDENCIES:
2424
- webview_flutter (from `.symlinks/plugins/webview_flutter/ios`)
2525

2626
SPEC REPOS:
27-
https://github.com/CocoaPods/Specs.git:
27+
https://github.com/cocoapods/specs.git:
2828
- FMDB
2929

3030
EXTERNAL SOURCES:
@@ -52,4 +52,4 @@ SPEC CHECKSUMS:
5252

5353
PODFILE CHECKSUM: 545ae53bd1d0bdac26cae6ddb8a02d47a0916981
5454

55-
COCOAPODS: 1.8.4
55+
COCOAPODS: 1.7.3

lib/components/index_bar/mh_index_bar.dart

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ class MHIndexBar extends StatefulWidget {
3737
fontSize: 10.0, color: Color(0xFF555555), fontWeight: FontWeight.w500),
3838
this.selectedTextStyle = const TextStyle(
3939
fontSize: 10.0, color: Color(0xFFFFFFFF), fontWeight: FontWeight.w500),
40-
this.hintOffsetX = 20.0,
40+
this.hintOffsetX = -80.0,
41+
this.hintOffsetY = -17.0,
42+
this.hintImagePath,
43+
this.hintContentAlignment = const Alignment(-0.25, 0.0),
4144
this.indexBarTagBuilder,
4245
this.indexBarHintBuilder,
4346
});
@@ -93,9 +96,18 @@ class MHIndexBar extends StatefulWidget {
9396
/// Item touch callback.
9497
final IndexBarTouchCallback onTouch;
9598

96-
/// hint右侧距离indexBar左侧的边距 默认是20.0
99+
/// hint左距离indexBar左侧的边距 默认是-80.0 = -(hintW + 20) // hintW = 60
97100
final double hintOffsetX;
98101

102+
/// hint顶部距离indexBar顶部侧的边距 默认是-17.0 = -(hintH - itemHeight) * 0.5 // hintH = 50, itemHeight = 16
103+
final double hintOffsetY;
104+
105+
/// hint背景图 只支持本地图片
106+
final String hintImagePath;
107+
108+
/// hint内容对其方式
109+
final Alignment hintContentAlignment;
110+
99111
/// 自定义标签,且 跟标签相关的属性将全部失效
100112
final IndexBarTagBuilder indexBarTagBuilder;
101113

@@ -135,6 +147,9 @@ class _SuspensionListViewIndexBarState extends State<MHIndexBar> {
135147
textStyle: widget.textStyle,
136148
selectedTextStyle: widget.selectedTextStyle,
137149
hintOffsetX: widget.hintOffsetX,
150+
hintOffsetY: widget.hintOffsetY,
151+
hintImagePath: widget.hintImagePath,
152+
hintContentAlignment: widget.hintContentAlignment,
138153
tagColor: widget.tagColor,
139154
selectedTagColor: widget.selectedTagColor,
140155
indexBarTagBuilder: widget.indexBarTagBuilder,
@@ -194,9 +209,18 @@ class _IndexBar extends StatefulWidget {
194209
/// Item touch callback.
195210
final IndexBarTouchCallback onTouch;
196211

197-
/// hint右侧距离indexBar左侧的边距 默认是20.0
212+
/// hint左距离indexBar左侧的边距 默认是-80.0 = -(hintW + 20) // hintW = 60
198213
final double hintOffsetX;
199214

215+
/// hint顶部距离indexBar顶部侧的边距 默认是-17.0 = -(hintH - itemHeight) * 0.5 // hintH = 50, itemHeight = 16
216+
final double hintOffsetY;
217+
218+
/// hint背景图 只支持本地图片
219+
final String hintImagePath;
220+
221+
/// hint内容对其方式
222+
final Alignment hintContentAlignment;
223+
200224
/// 标签默认的背景色 默认是透明色
201225
final Color tagColor;
202226

@@ -226,9 +250,12 @@ class _IndexBar extends StatefulWidget {
226250
fontSize: 10.0, color: Color(0xFF555555), fontWeight: FontWeight.w500),
227251
this.selectedTextStyle = const TextStyle(
228252
fontSize: 10.0, color: Color(0xFFFFFFFF), fontWeight: FontWeight.w500),
229-
this.hintOffsetX = 20.0,
253+
this.hintOffsetX = -80.0,
254+
this.hintOffsetY = -17.0,
230255
this.tagColor = Colors.transparent,
231256
this.selectedTagColor = const Color(0xFF07C160),
257+
this.hintImagePath,
258+
this.hintContentAlignment = const Alignment(-0.25, 0.0),
232259
this.indexBarTagBuilder,
233260
this.indexBarHintBuilder,
234261
}) : assert(onTouch != null),
@@ -348,11 +375,12 @@ class _IndexBarState extends State<_IndexBar> {
348375
return Text(
349376
tag,
350377
textAlign: TextAlign.center,
351-
style: TextStyle(
352-
fontSize: 10.0,
353-
color: Color(0xFF555555),
354-
fontWeight: FontWeight.w500,
355-
),
378+
style: widget.textStyle ??
379+
TextStyle(
380+
fontSize: 10.0,
381+
color: Color(0xFF555555),
382+
fontWeight: FontWeight.w500,
383+
),
356384
);
357385
}
358386
} else {
@@ -361,18 +389,19 @@ class _IndexBarState extends State<_IndexBar> {
361389
// 返回映射高亮的部件
362390
return widget.mapSelTag[tag];
363391
} else if (widget.mapTag != null && widget.mapTag[tag] != null) {
364-
// 返回映射的部件
392+
// 返回映射默认的部件
365393
return widget.mapTag[tag];
366394
} else {
367395
// 返回默认的部件
368396
return Text(
369397
tag,
370398
textAlign: TextAlign.center,
371-
style: TextStyle(
372-
fontSize: 10.0,
373-
color: Colors.white,
374-
fontWeight: FontWeight.w500,
375-
),
399+
style: widget.selectedTextStyle ??
400+
TextStyle(
401+
fontSize: 10.0,
402+
color: Colors.white,
403+
fontWeight: FontWeight.w500,
404+
),
376405
);
377406
}
378407
}
@@ -387,37 +416,41 @@ class _IndexBarState extends State<_IndexBar> {
387416
return Text(
388417
tag,
389418
textAlign: TextAlign.center,
390-
style: TextStyle(
391-
fontSize: 10.0,
392-
color: Color(0xFF555555),
393-
fontWeight: FontWeight.w500,
394-
),
419+
style: widget.textStyle ??
420+
TextStyle(
421+
fontSize: 10.0,
422+
color: Color(0xFF555555),
423+
fontWeight: FontWeight.w500,
424+
),
395425
);
396426
}
397427
}
398428

399-
/// 构建tag
429+
/// 构建indexBar hint
400430
Widget _buildIndexBarHintWidget(
401431
BuildContext context, String tag, IndexBarDetails indexModel) {
432+
// 如果外界自定义 indexbarHint
402433
if (widget.indexBarHintBuilder != null) {
403434
return widget.indexBarHintBuilder(context, tag, indexModel);
404435
} else {
436+
// 图片路径
437+
final String hintImagePath = widget.hintImagePath ??
438+
'assets/images/contacts/ContactIndexShape_60x50.png';
405439
return Positioned(
406-
left: -(60 + widget.hintOffsetX ?? 20),
407-
top: -(50 - widget.itemHeight) * 0.5,
440+
left: widget.hintOffsetX ?? -80,
441+
top: widget.hintOffsetY ?? -(50 - widget.itemHeight) * 0.5,
408442
child: Offstage(
409443
offstage: _fetchOffstage(tag),
410444
child: Container(
411445
width: 60.0,
412446
height: 50.0,
413447
decoration: BoxDecoration(
414448
image: DecorationImage(
415-
image: AssetImage(
416-
'assets/images/contacts/ContactIndexShape_60x50.png'),
449+
image: AssetImage(hintImagePath),
417450
fit: BoxFit.contain,
418451
),
419452
),
420-
alignment: Alignment(-0.25, 0.0),
453+
alignment: widget.hintContentAlignment ?? Alignment(-0.25, 0.0),
421454
child: _buildHintChildWidget(tag),
422455
),
423456
),

0 commit comments

Comments
 (0)