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
| import 'package:azlistview/azlistview.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
class AzListViewWidget extends StatefulWidget { final List<ISuspensionBean> dataList; final void Function(dynamic) onTap; const AzListViewWidget( {super.key, required this.dataList, required this.onTap});
@override State<AzListViewWidget> createState() => _AzListViewWidgetState(); }
class _AzListViewWidgetState extends State<AzListViewWidget> { @override void initState() { print("initState ${widget.dataList}"); super.initState(); }
@override Widget build(BuildContext context) { return widget.dataList.isEmpty ? Center( child: Text( "暂无数据", style: TextStyle(fontSize: 15.sp, color: Colors.grey[400]), ), ) : AzListView( data: widget.dataList, itemCount: widget.dataList.length, itemBuilder: (BuildContext context, int index) { dynamic model = widget.dataList[index];
return getWeChatItem(context, model, widget.onTap); }, physics: const BouncingScrollPhysics(), susItemBuilder: (BuildContext context, int index) { dynamic model = widget.dataList[index]; if ('↑' == model.getSuspensionTag()) { return Container(); } return getSusItem(context, model.getSuspensionTag()); }, indexBarData: const ['↑', '☆', ...kIndexBarData], indexBarOptions: IndexBarOptions( needRebuild: true, ignoreDragCancel: true, downTextStyle: const TextStyle(fontSize: 12, color: Colors.white), downItemDecoration: const BoxDecoration( shape: BoxShape.circle, color: Colors.green), indexHintWidth: ScreenUtil().setWidth(120 / 2), indexHintHeight: ScreenUtil().setHeight(100 / 2),
indexHintAlignment: Alignment.centerRight, indexHintChildAlignment: const Alignment(-0.25, 0.0), indexHintOffset: const Offset(-20, 0), ), ); } }
Widget getWeChatItem( BuildContext context, dynamic model, void Function(dynamic item) onTap) { DecorationImage? image; return ListTile( leading: Container( width: 36.w, height: 36.h, decoration: BoxDecoration( shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(4.0), color: Colors.blue[200], image: image, ), child: const Icon(Icons.abc_sharp), ), title: Text(model.name), onTap: () { onTap(model); }, ); }
Widget getSusItem(BuildContext context, String tag, {double susHeight = 40}) { if (tag == '★') { tag = '★ 热门城市'; } return Container( height: ScreenUtil().setHeight(susHeight), width: MediaQuery.of(context).size.width, padding: const EdgeInsets.only(left: 16.0), color: const Color(0xFFF3F4F5), alignment: Alignment.centerLeft, child: Text( tag, softWrap: false, style: const TextStyle( fontSize: 14.0, color: Color(0xFF666666), ), ), ); }
|