Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.3 kB
5
Indexable
Never
import 'package:beamer/beamer.dart';
import 'package:flutter/material.dart';
import 'package:myproject/items/model/item.dart';

class MyItemList extends StatelessWidget {
  const MyItemList(this.data, {super.key});

  final List<MyItem> data;

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemCount: data.length,
      itemBuilder: (context, index) {
        final item = data[index];
        return MyItemWidget(item);
      },
    );
  }
}

class MyItemWidget extends StatelessWidget {
  const MyItemWidget(this.item, {super.key});

  final MyItem item;

  @override
  Widget build(BuildContext context) {
    final textTheme = Theme.of(context).textTheme;
    return InkWell(
      onTap: () {
        context.beamToNamed('/items/${item.id}');
      },
      child: Container(
        padding: const EdgeInsets.all(8),
        decoration: const BoxDecoration(
          border: Border(top: BorderSide(color: Colors.grey)),
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(
              width: 64,
              height: 64,
              child: ClipRRect(
                borderRadius: const BorderRadius.all(Radius.circular(8)),
                child: Image.network(item.image, fit: BoxFit.cover),
              ),
            ),
            const SizedBox(width: 12),
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  item.name,
                  style: textTheme.bodyLarge
                      ?.copyWith(fontWeight: FontWeight.bold),
                ),
                const Text('Title'),
                const Row(
                  children: [
                    Icon(Icons.star, color: Colors.amber, size: 18),
                    SizedBox(width: 4),
                    Text('bla'),
                  ],
                ),
                Text(
                  item.description,
                  overflow: TextOverflow.ellipsis,
                  maxLines: 1,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
Leave a Comment