1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 13:37:29 +01:00

Add search bar to title bar

This commit is contained in:
Oystein Kristoffer Tveit 2020-07-14 14:33:21 +02:00
parent 9204ce4cfd
commit bd87af4a38
2 changed files with 58 additions and 33 deletions

View File

@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
import 'package:jisho_study_tool/screens/kanji_search.dart';
import 'package:jisho_study_tool/screens/history.dart';
import 'package:jisho_study_tool/screens/search.dart';
import 'bloc/search/search_bloc.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@ -14,7 +18,13 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
home: MultiBlocProvider(
providers: [
BlocProvider(create: (context) => SearchBloc()),
BlocProvider(create: (context) => KanjiBloc()),
],
child: Home(),
),
);
}
}
@ -82,14 +92,14 @@ class Page {
Widget content;
Widget titleBar;
Page({ this.content,this.titleBar,});
Page({
this.content,
this.titleBar,
});
}
final List<Page> pages = [
Page(
content: SearchView(),
titleBar: Text('Search')
),
Page(content: SearchView(), titleBar: Text('Search')),
Page(
content: KanjiView(),
titleBar: KanjiViewBar(),

View File

@ -6,24 +6,17 @@ import 'package:jisho_study_tool/components/kanji/kanji__search_page/kanji_searc
import 'package:jisho_study_tool/components/loading.dart';
class KanjiView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => KanjiBloc(),
child: _KanjiSearchPage(),
);
}
}
class _KanjiSearchPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<KanjiBloc, KanjiState>(
builder: (context, state) {
if (state is KanjiSearchInitial) return KanjiSearchBar();
else if (state is KanjiSearchLoading) return LoadingScreen();
else if (state is KanjiSearchFinished) return KanjiResultCard(state.kanji);
if (state is KanjiSearchInitial)
return Container();
else if (state is KanjiSearchLoading)
return LoadingScreen();
else if (state is KanjiSearchFinished)
return KanjiResultCard(state.kanji);
throw 'No such event found';
},
);
@ -31,23 +24,45 @@ class _KanjiSearchPage extends StatelessWidget {
}
class KanjiViewBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text('Kanji');
}
}
class KanjiSearchBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: TextField(
onSubmitted: (text) => BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
decoration: new InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'Search for kanji'
child: Container(
child: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () => BlocProvider.of<KanjiBloc>(context)
.add(ReturnToInitialState()),
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
onSubmitted: (text) =>
BlocProvider.of<KanjiBloc>(context).add(GetKanji(text)),
decoration: new InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'Search for kanji',
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(100.0)),
),
),
),
),
IconButton(
icon: Icon(Icons.star_border),
onPressed: null,
),
IconButton(
icon: Icon(Icons.add),
onPressed: null,
),
],
),
),
);
}
}
}