Skip to content

Commit

Permalink
部分ListView指定itemExtent大小
Browse files Browse the repository at this point in the history
  • Loading branch information
simplezhli committed Aug 4, 2019
1 parent 2df8da9 commit d4bbd37
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/account/withdrawal_account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class _WithdrawalAccountPageState extends State<WithdrawalAccountPage> {
ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 22.0),
itemCount: _list.length,
itemExtent: 151.0,
itemBuilder: (_, index){
return Padding(
padding: const EdgeInsets.only(top: 15.0),
Expand All @@ -53,7 +54,6 @@ class _WithdrawalAccountPageState extends State<WithdrawalAccountPage> {
_showDeleteBottomSheet(index);
},
child: Container(
height: 136.0,
child: Stack(
children: <Widget>[
Positioned(
Expand Down
2 changes: 1 addition & 1 deletion lib/goods/goods_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _GoodsListState extends State<GoodsList> with AutomaticKeepAliveClientMixi
Widget build(BuildContext context) {
super.build(context);
return DeerListView(
data: _list,
itemCount: _list.length,
stateType: _stateType,
onRefresh: _onRefresh,
loadMore: _loadMore,
Expand Down
1 change: 1 addition & 0 deletions lib/goods/goods_size_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class _GoodsSizeState extends State<GoodsSize> {
hintText: "暂无商品规格",
) : ListView.builder(
itemCount: goodsSizeList.length,
itemExtent: 105.0,
itemBuilder: (_, index){
return getGoodsSizeItem(index);
},
Expand Down
2 changes: 1 addition & 1 deletion lib/goods/goods_sort_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ class _GoodsSortDialogState extends State<GoodsSortDialog> with SingleTickerProv
Expanded(
child: ListView.builder(
controller: _controller,
itemExtent: 48.0,
itemBuilder: (_, index){
return InkWell(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16.0),
height: 48.0,
alignment: Alignment.centerLeft,
child: Row(
children: <Widget>[
Expand Down
4 changes: 2 additions & 2 deletions lib/order/order_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class OrderSearchState extends BasePageState<OrderSearch, OrderSearchPresenter>
body: Consumer<SearchItemListProvider>(
builder: (_, provider, __) {
return DeerListView(
data: provider.list,
itemCount: provider.list.length,
stateType: provider.stateType,
onRefresh: _onRefresh,
loadMore: _loadMore,
itemExtent: 50.0,
hasMore: provider.hasMore,
itemBuilder: (_, index){
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
height: 50.0,
alignment: Alignment.centerLeft,
child: Text(provider.list[index].name),
);
Expand Down
3 changes: 1 addition & 2 deletions lib/shop/freight_config_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class _FreightConfigPageState extends State<FreightConfigPage> {
right: 0.0,
bottom: 64.0,
child: ListView.builder(
itemExtent: 110.0,
padding: const EdgeInsets.only(left: 16.0, right: 16.0),
itemBuilder: (_, index){
return _buildItem(index);
Expand Down Expand Up @@ -96,7 +97,6 @@ class _FreightConfigPageState extends State<FreightConfigPage> {
}
},
child: Container(
height: 100.0,
margin: const EdgeInsets.only(bottom: 8.0),
padding: const EdgeInsets.symmetric(vertical: 32.0),
decoration: BoxDecoration(
Expand All @@ -107,7 +107,6 @@ class _FreightConfigPageState extends State<FreightConfigPage> {
),
) : Container(
margin: const EdgeInsets.only(bottom: 8.0),
height: 103.0,
child: MyCard(
child: Padding(
padding: const EdgeInsets.all(15.0),
Expand Down
2 changes: 1 addition & 1 deletion lib/store/store_audit_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ class _StoreAuditState extends State<StoreAudit> {
return Container(
height: 360.0,
child: ListView.builder(
itemExtent: 48.0,
itemBuilder: (_, index){
return InkWell(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
height: 48.0,
alignment: Alignment.centerLeft,
child: Text(_list[index]),
),
Expand Down
20 changes: 13 additions & 7 deletions lib/widgets/my_refresh_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@ class DeerListView extends StatefulWidget {

const DeerListView({
Key key,
@required this.data,
@required this.itemCount,
@required this.itemBuilder,
@required this.onRefresh,
this.loadMore,
this.hasMore : false,
this.stateType : StateType.empty,
this.pageSize : 10
this.pageSize : 10,
this.padding,
this.itemExtent
}): super(key: key);

final RefreshCallback onRefresh;
final LoadMoreCallback loadMore;
final List data;
final int itemCount;
final bool hasMore;
final IndexedWidgetBuilder itemBuilder;
final StateType stateType;
/// 一页的数量,默认为10
final int pageSize;
final EdgeInsetsGeometry padding;
final double itemExtent;

@override
_DeerListViewState createState() => _DeerListViewState();
Expand All @@ -51,10 +55,12 @@ class _DeerListViewState extends State<DeerListView> {
},
child: RefreshIndicator(
onRefresh: widget.onRefresh,
child: widget.data.isEmpty ? StateLayout(type: widget.stateType) : ListView.builder(
itemCount: widget.data.length + 1,
child: widget.itemCount == 0 ? StateLayout(type: widget.stateType) : ListView.builder(
itemCount: widget.itemCount + 1,
padding: widget.padding,
itemExtent: widget.itemExtent,
itemBuilder: (BuildContext context, int index){
return index < widget.data.length ? widget.itemBuilder(context, index) : _buildMoreWidget();
return index < widget.itemCount ? widget.itemBuilder(context, index) : _buildMoreWidget();
}
)
),
Expand Down Expand Up @@ -87,7 +93,7 @@ class _DeerListViewState extends State<DeerListView> {
Offstage(offstage: !widget.hasMore, child: const CupertinoActivityIndicator()),
Offstage(offstage: !widget.hasMore, child: Gaps.hGap5),
/// 只有一页的时候,就不显示FooterView了
Text(widget.hasMore ? '正在加载中...' : (widget.data.length < widget.pageSize ? '' : '没有了呦~'), style: TextStyle(color: const Color(0x8A000000))),
Text(widget.hasMore ? '正在加载中...' : (widget.itemCount < widget.pageSize ? '' : '没有了呦~'), style: TextStyle(color: const Color(0x8A000000))),
],
),
);
Expand Down

0 comments on commit d4bbd37

Please sign in to comment.