依赖
flutter_staggered_grid_view: ^0.7.0 #flutter瀑布流
代码例子
Widget _bestContent() { return Obx(() => Container( child: Column( children: [ Container( color: Colors.yellow, height: ScreenAdapter.height(500), width: ScreenAdapter.width(500), child: MasonryGridView.count( crossAxisCount: 2, //列 mainAxisSpacing: ScreenAdapter.height(50), //高度间距 crossAxisSpacing: ScreenAdapter.width(50), //宽度间距 itemCount: controller.homeController.vocabularyList.length, shrinkWrap: true, //收缩自适应 // physics: const NeverScrollableScrollPhysics(), //禁止左右滑动 itemBuilder: (context, index) { return Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(15)), color: Colors.white, border: Border.all( color: Colors.black, width: 0.8, ), ), child: ConstrainedBox( constraints: BoxConstraints( minHeight: ScreenAdapter.height(300), // 设置最小高度 ), child: Text( "$index ${controller.homeController.vocabularyList[index].dclj}", style: TextStyle( fontFamily: '${controller.homeController.motifsModelItem.value.textFont}', fontSize: ScreenAdapter.fontSize(50), fontWeight: FontWeight.bold, // 设置字重 ), ), )); }, ), ) ], ), )); }