Skip to content

Instantly share code, notes, and snippets.

@bullheadandplato
Created May 25, 2022 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bullheadandplato/51e0d50ccd1fd868a01971ddd500e0f8 to your computer and use it in GitHub Desktop.
Save bullheadandplato/51e0d50ccd1fd868a01971ddd500e0f8 to your computer and use it in GitHub Desktop.
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:ticaret_yeri/domain/ad/ad_info.dart';
class HighlightView extends StatelessWidget {
final List<AdInfo> highlights;
const HighlightView({Key? key, required this.highlights}) : super(key: key);
@override
Widget build(BuildContext context) {
return highlights.isEmpty
? const SizedBox.shrink()
: GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
childAspectRatio: 1 / 0.4,
physics: const NeverScrollableScrollPhysics(),
children: highlights
.mapIndexed((index, e) => _HighlightItemView(
info: e,
index: index,
))
.toList());
}
}
class _HighlightItemView extends StatelessWidget {
final AdInfo info;
final int index;
const _HighlightItemView({Key? key, required this.info, required this.index})
: super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.black.withAlpha(20)),
left: index % 2 == 0
? BorderSide.none
: BorderSide(color: Colors.black.withAlpha(20))),
color: const Color(0xfffff9f5)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
info.name,
style: theme.textTheme.bodySmall
?.copyWith(color: theme.primaryColor),
textAlign: TextAlign.center,
),
const SizedBox(
height: 2,
),
Text(
info.value,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodySmall?.copyWith(color: Colors.black),
textAlign: TextAlign.center,
),
]),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment