Jisho-Study-Tool/lib/view/components/history/kanji_search_item.dart

85 lines
2.1 KiB
Dart
Raw Normal View History

2021-07-19 01:49:18 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
2021-08-03 22:02:42 +02:00
import './search_item.dart';
2021-12-01 23:09:53 +01:00
import '../../../bloc/theme/theme_bloc.dart';
import '../../../models/history/kanji_query.dart';
import '../../../models/themes/theme.dart';
2021-07-19 01:49:18 +02:00
2021-08-03 22:02:42 +02:00
class _KanjiBox extends StatelessWidget {
final String kanji;
const _KanjiBox(this.kanji);
2021-07-19 01:49:18 +02:00
@override
Widget build(BuildContext context) {
2021-12-06 20:26:52 +01:00
final ColorSet _menuColors =
BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyLight;
2021-08-08 23:16:54 +02:00
2021-08-03 22:02:42 +02:00
return IntrinsicHeight(
child: AspectRatio(
aspectRatio: 1,
child: Container(
2021-12-01 23:09:53 +01:00
padding: const EdgeInsets.all(5),
2021-08-03 22:02:42 +02:00
decoration: BoxDecoration(
2021-08-08 23:16:54 +02:00
color: _menuColors.background,
2021-08-03 22:02:42 +02:00
borderRadius: BorderRadius.circular(10.0),
),
child: Center(
child: FittedBox(
child: Text(
kanji,
style: TextStyle(
2021-08-08 23:16:54 +02:00
color: _menuColors.foreground,
2021-08-03 22:02:42 +02:00
fontSize: 25,
),
),
),
),
),
),
);
2021-07-19 01:49:18 +02:00
}
}
class KanjiSearchItem extends StatelessWidget {
2021-08-03 22:02:42 +02:00
final KanjiQuery result;
final DateTime timestamp;
2021-07-19 01:49:18 +02:00
2021-08-03 22:02:42 +02:00
const KanjiSearchItem({
required this.result,
required this.timestamp,
Key? key,
}) : super(key: key);
2021-07-19 01:49:18 +02:00
@override
Widget build(BuildContext context) {
return Slidable(
2021-12-06 20:26:52 +01:00
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
label: 'Favourite',
backgroundColor: Colors.yellow,
icon: Icons.star,
onPressed: (_) {},
),
SlidableAction(
label: 'Delete',
backgroundColor: Colors.red,
icon: Icons.delete,
onPressed: (_) {},
),
],
),
2021-12-04 05:22:58 +01:00
child: SearchItem(
onTap: () {
Navigator.pushNamed(context, '/kanjiSearch', arguments: result.kanji);
},
time: timestamp,
search: _KanjiBox(result.kanji),
),
2021-07-19 01:49:18 +02:00
);
}
}