57 lines
1.7 KiB
Dart
57 lines
1.7 KiB
Dart
// Author: fengshengxiong
|
|
// Date: 2024/5/11
|
|
// Description: 瀑布流
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
|
import 'package:wallpaper/common/components/image_widget.dart';
|
|
import 'package:wallpaper/common/components/view_state_widget.dart';
|
|
import 'package:wallpaper/common/models/wallpaper_model.dart';
|
|
|
|
class BaseMasonryGridView extends StatelessWidget {
|
|
const BaseMasonryGridView({
|
|
super.key,
|
|
this.viewState = ViewState.normal,
|
|
required this.wallpaperList,
|
|
required this.itemOnTap,
|
|
this.onLongPress,
|
|
});
|
|
|
|
final List<WallpaperData> wallpaperList;
|
|
final Function(int index) itemOnTap;
|
|
final Function(int index)? onLongPress;
|
|
final ViewState? viewState;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ViewStateWidget(
|
|
state: viewState!,
|
|
child: MasonryGridView.count(
|
|
itemCount: wallpaperList.length,
|
|
crossAxisCount: 2,
|
|
mainAxisSpacing: 8.w,
|
|
crossAxisSpacing: 8.w,
|
|
physics: const BouncingScrollPhysics(),
|
|
padding: const EdgeInsets.symmetric(horizontal: 8).w,
|
|
itemBuilder: (context, index) {
|
|
return _wallpaperItem(wallpaperList[index], index);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _wallpaperItem(WallpaperData item, index) {
|
|
return InkWell(
|
|
onTap: () => itemOnTap(index),
|
|
borderRadius: BorderRadius.circular(8).r,
|
|
onLongPress: onLongPress != null ? () => onLongPress!(index) : null,
|
|
child: ImageWidget(
|
|
url: item.previewThumb,
|
|
fit: BoxFit.contain,
|
|
radius: 8.r,
|
|
),
|
|
);
|
|
}
|
|
}
|