|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_svg/svg.dart'; |
| 3 | +import 'package:gap/gap.dart'; |
| 4 | +import 'package:qack/layout/layout_handler.dart'; |
| 5 | +import 'package:qack/presentation/history/models/models.dart'; |
| 6 | +import 'package:qack/presentation/settings/models/models.dart'; |
| 7 | +import 'package:qack/theme/theme.dart'; |
| 8 | +import 'package:vector_graphics/vector_graphics.dart'; |
| 9 | + |
| 10 | +class HistoryListTile extends StatefulWidget { |
| 11 | + const HistoryListTile({required this.translationHistory, super.key}); |
| 12 | + final TranslationHistory translationHistory; |
| 13 | + |
| 14 | + @override |
| 15 | + State<HistoryListTile> createState() => _HistoryListTileState(); |
| 16 | +} |
| 17 | + |
| 18 | +class _HistoryListTileState extends State<HistoryListTile> { |
| 19 | + @override |
| 20 | + Widget build(BuildContext context) { |
| 21 | + const theme = LightTheme(); |
| 22 | + return LayoutHandler( |
| 23 | + mobile: HistoryListTileView( |
| 24 | + translationHistory: widget.translationHistory, |
| 25 | + theme: theme, |
| 26 | + cardMargin: const EdgeInsets.only(bottom: 16), |
| 27 | + cardPadding: |
| 28 | + const EdgeInsets.only(top: 12, left: 12, right: 12, bottom: 12), |
| 29 | + titleGap: 8, |
| 30 | + translationInputStyle: AppTextStyle.textMD.semiBold.copyWith( |
| 31 | + color: theme.textColor1, |
| 32 | + ), |
| 33 | + translationOutputStyle: AppTextStyle.textMD.medium.copyWith( |
| 34 | + color: theme.textColor1, |
| 35 | + ), |
| 36 | + ), |
| 37 | + tablet: HistoryListTileView( |
| 38 | + translationHistory: widget.translationHistory, |
| 39 | + theme: theme, |
| 40 | + cardMargin: const EdgeInsets.only(bottom: 16), |
| 41 | + cardPadding: |
| 42 | + const EdgeInsets.only(top: 12, left: 12, right: 12, bottom: 12), |
| 43 | + titleGap: 8, |
| 44 | + translationInputStyle: AppTextStyle.textMD.semiBold.copyWith( |
| 45 | + color: theme.textColor1, |
| 46 | + ), |
| 47 | + translationOutputStyle: AppTextStyle.textMD.medium.copyWith( |
| 48 | + color: theme.textColor1, |
| 49 | + ), |
| 50 | + ), |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +class HistoryListTileView extends StatelessWidget { |
| 56 | + const HistoryListTileView({ |
| 57 | + required this.translationHistory, |
| 58 | + required this.theme, |
| 59 | + required this.cardMargin, |
| 60 | + required this.cardPadding, |
| 61 | + required this.titleGap, |
| 62 | + required this.translationInputStyle, |
| 63 | + required this.translationOutputStyle, |
| 64 | + super.key, |
| 65 | + }); |
| 66 | + final TranslationHistory translationHistory; |
| 67 | + |
| 68 | + final BaseTheme theme; |
| 69 | + final EdgeInsets cardMargin; |
| 70 | + final EdgeInsets cardPadding; |
| 71 | + final double titleGap; |
| 72 | + final TextStyle translationInputStyle; |
| 73 | + final TextStyle translationOutputStyle; |
| 74 | + |
| 75 | + @override |
| 76 | + Widget build(BuildContext context) { |
| 77 | + return Padding( |
| 78 | + padding: cardMargin, |
| 79 | + child: DecoratedBox( |
| 80 | + decoration: BoxDecoration( |
| 81 | + color: theme.cardColor, |
| 82 | + boxShadow: theme.cardShadow, |
| 83 | + borderRadius: BorderRadius.circular(4), |
| 84 | + ), |
| 85 | + child: Padding( |
| 86 | + padding: cardPadding, |
| 87 | + child: Column( |
| 88 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 89 | + children: [ |
| 90 | + Text( |
| 91 | + translationHistory.input, |
| 92 | + style: translationInputStyle, |
| 93 | + ), |
| 94 | + ...List.generate( |
| 95 | + translationHistory.items?.length ?? 0, |
| 96 | + (index) { |
| 97 | + final translator = translationHistory.items! |
| 98 | + .elementAt(index) |
| 99 | + .translator |
| 100 | + .toTranslator(); |
| 101 | + |
| 102 | + late final EdgeInsets padding; |
| 103 | + |
| 104 | + if (index == 0) { |
| 105 | + padding = const EdgeInsets.only(top: 8, bottom: 12); |
| 106 | + } else if (index == translationHistory.items!.length - 1) { |
| 107 | + padding = const EdgeInsets.only(bottom: 8); |
| 108 | + } else { |
| 109 | + padding = const EdgeInsets.only(bottom: 12); |
| 110 | + } |
| 111 | + |
| 112 | + return Padding( |
| 113 | + padding: padding, |
| 114 | + child: Row( |
| 115 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 116 | + children: [ |
| 117 | + SizedBox( |
| 118 | + height: 28, |
| 119 | + width: 28, |
| 120 | + child: SvgPicture( |
| 121 | + AssetBytesLoader( |
| 122 | + translator.svgPath, |
| 123 | + ), |
| 124 | + ), |
| 125 | + ), |
| 126 | + Gap(titleGap), |
| 127 | + Expanded( |
| 128 | + child: Text( |
| 129 | + translationHistory.items! |
| 130 | + .elementAt(index) |
| 131 | + .output |
| 132 | + .trim(), |
| 133 | + style: translationOutputStyle, |
| 134 | + ), |
| 135 | + ), |
| 136 | + ], |
| 137 | + ), |
| 138 | + ); |
| 139 | + }, |
| 140 | + ), |
| 141 | + ], |
| 142 | + ), |
| 143 | + ), |
| 144 | + ), |
| 145 | + ); |
| 146 | + } |
| 147 | +} |
0 commit comments