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

80 lines
2.0 KiB
Dart
Raw Normal View History

2021-07-19 01:49:18 +02:00
import 'package:flutter/material.dart';
2021-08-03 22:02:42 +02:00
import 'package:flutter_bloc/flutter_bloc.dart';
2021-07-19 01:49:18 +02:00
import 'package:flutter_slidable/flutter_slidable.dart';
2021-08-03 22:02:42 +02:00
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
import 'package:jisho_study_tool/bloc/navigation/navigation_bloc.dart';
import 'package:jisho_study_tool/models/history/kanji_query.dart';
2021-07-19 01:49:18 +02:00
2021-08-03 22:02:42 +02:00
import './search_item.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-08-03 22:02:42 +02:00
return IntrinsicHeight(
child: AspectRatio(
aspectRatio: 1,
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(10.0),
),
child: Center(
child: FittedBox(
child: Text(
kanji,
style: TextStyle(
color: Colors.black,
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-08-03 22:02:42 +02:00
child: SearchItem(
onTap: () {
BlocProvider.of<NavigationBloc>(context).add(ChangePage(1));
BlocProvider.of<KanjiBloc>(context).add(GetKanji(this.result.kanji));
},
time: timestamp,
search: _KanjiBox(result.kanji),
),
2021-07-19 01:49:18 +02:00
actionPane: SlidableScrollActionPane(),
secondaryActions: [
IconSlideAction(
caption: "Favourite",
color: Colors.yellow,
2021-08-03 22:02:42 +02:00
icon: Icons.star,
2021-07-19 01:49:18 +02:00
),
IconSlideAction(
caption: "Delete",
color: Colors.red,
2021-08-03 22:02:42 +02:00
icon: Icons.delete,
),
2021-07-19 01:49:18 +02:00
],
);
}
}