Jisho-Study-Tool/lib/view/components/kanji/kanji_grid.dart

54 lines
1.3 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
2021-07-17 12:19:03 +02:00
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
2021-07-17 12:19:03 +02:00
class KanjiGrid extends StatelessWidget {
2021-03-03 00:24:25 +01:00
final List<String> suggestions;
2021-07-17 12:19:03 +02:00
const KanjiGrid(this.suggestions);
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 40.0,
),
child: GridView.count(
crossAxisCount: 3,
2021-07-17 12:19:03 +02:00
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
children: suggestions.map((kanji) => _GridItem(kanji)).toList(),
),
);
}
}
2021-07-17 12:19:03 +02:00
class _GridItem extends StatelessWidget {
2021-03-03 00:24:25 +01:00
final String kanji;
2021-07-17 12:19:03 +02:00
const _GridItem(this.kanji);
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
2021-03-03 00:24:25 +01:00
BlocProvider.of<KanjiBloc>(context).add(GetKanji(kanji));
},
child: Container(
decoration: BoxDecoration(
2021-07-17 12:19:03 +02:00
color: Colors.grey[300],
borderRadius: BorderRadius.circular(20.0),
),
child: Container(
margin: EdgeInsets.all(10.0),
child: FittedBox(
child: Text(
2021-03-03 00:24:25 +01:00
kanji,
2021-07-17 12:19:03 +02:00
style: TextStyle(color: Colors.black),
),
),
),
),
);
}
2021-07-17 12:19:03 +02:00
}