123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- import 'package:canteen/model/dish_model.dart';
- import 'package:flutter/material.dart';
- /// Description: 食堂菜谱
- /// Time : 07/25/2022 Monday
- /// Author : liuyuqi.gov@msn.cn
- class CanteenDishListView extends StatelessWidget {
- final List<DishModel> dishes;
- final void Function(int index)? onLikePressed;
- final void Function(int index)? onStarPressed;
- CanteenDishListView(this.dishes,
- {this.onLikePressed = null, this.onStarPressed = null});
- @override
- Widget build(BuildContext context) {
- /// 列表
- return ListView.separated(
- shrinkWrap: true,
- addRepaintBoundaries: true,
- itemCount: dishes.length,
- itemBuilder: (BuildContext context, int index) {
- return _DishListViewItem(
- index, dishes[index], onLikePressed, onStarPressed);
- },
- separatorBuilder: (context, index) {
- return const Divider(color: Colors.grey);
- },
- );
- }
- }
- class _DishListViewItem extends StatelessWidget {
- final int id;
- final DishModel dish;
- final void Function(int index)? onLikePressed;
- final void Function(int index)? onStarPressed;
- const _DishListViewItem(
- this.id, this.dish, this.onLikePressed, this.onStarPressed);
- @override
- //5:3=20:12
- //4:3=12:9
- Widget build(BuildContext context) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- Expanded(
- child: Column(
- children: [
- Padding(
- child: Row(
- children: [
- Text(
- dish.name,
- textScaleFactor: 2,
- ),
- Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- Padding(
- child: Text(
- dish.cost,
- textScaleFactor: 1.2,
- ),
- padding: EdgeInsets.fromLTRB(0, 0, 16, 0),
- )
- ]))
- ],
- ),
- padding: EdgeInsets.fromLTRB(6, 4, 4, 4)),
- Padding(
- child: Row(
- children: [
- Text(
- dish.canteen,
- textScaleFactor: 0.9,
- ),
- Expanded(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- Padding(
- child: Text(
- dish.time,
- textScaleFactor: 0.9,
- ),
- padding: EdgeInsets.fromLTRB(0, 0, 20, 0),
- )
- ]))
- ],
- ),
- padding: EdgeInsets.fromLTRB(6, 0, 0, 6),
- )
- ],
- ),
- ),
- IconButton(
- onPressed: () {
- if (onLikePressed != null) onLikePressed!(this.id);
- },
- icon: Icon(dish.like ? Icons.favorite : Icons.favorite_border,
- color: dish.like ? Colors.red : null)),
- IconButton(
- onPressed: () {
- if (onStarPressed != null) onStarPressed!(this.id);
- },
- icon: Icon(dish.star ? Icons.star : Icons.star_border,
- color: dish.star ? Colors.amber : null)),
- ],
- );
- }
- }
|