Update kanji screen

This commit is contained in:
Oystein Kristoffer Tveit 2020-06-30 22:51:32 +02:00
parent f0d8aabe0f
commit c90fbc2fee
4 changed files with 68 additions and 30 deletions

View File

@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart';
class KanjiGrid extends StatelessWidget {

View File

@ -11,7 +11,8 @@ class KanjiResultCard extends StatelessWidget {
return Container(
height: 100,
width: 100,
child: Text(_result.query),
child: Center(child:Text(_result.query)),
color: Colors.amber,
);
}

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:jisho_study_tool/screens/kanji_search.dart';
void main() => runApp(MyApp());
@ -29,9 +30,10 @@ class _HomeState extends State<Home> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Jisho Study Tool')
title: Text(pages[_selectedPage].title),
centerTitle: true,
),
body: Container(),
body: pages[_selectedPage].content,
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedPage,
onTap: (int index) {
@ -39,29 +41,7 @@ class _HomeState extends State<Home> {
_selectedPage = index;
});
},
items: [
BottomNavigationBarItem(
title: Text('Search'),
icon: Icon(Icons.search)
),
BottomNavigationBarItem(
title: Text('Kanji'),
icon: Text(
'',
style: TextStyle(
fontSize: 18
),
)
),
BottomNavigationBarItem(
title: Text('Memorize'),
icon: Icon(Icons.book)
),
BottomNavigationBarItem(
title: Text('Settings'),
icon: Icon(Icons.settings)
),
],
items: navBar,
showSelectedLabels: false,
showUnselectedLabels: false,
unselectedItemColor: Colors.blue,
@ -70,4 +50,57 @@ class _HomeState extends State<Home> {
);
}
}
}
List<BottomNavigationBarItem> navBar = [
BottomNavigationBarItem(
title: Text('Search'),
icon: Icon(Icons.search)
),
BottomNavigationBarItem(
title: Text('Kanji'),
icon: Text(
'',
style: TextStyle(
fontSize: 18
),
)
),
BottomNavigationBarItem(
title: Text('Memorize'),
icon: Icon(Icons.book)
),
BottomNavigationBarItem(
title: Text('Settings'),
icon: Icon(Icons.settings)
),
];
class Page {
String title;
Widget content;
Page({
this.title,
this.content
});
}
List<Page> pages = [
Page(
title: "Search",
content: Container()
),
Page(
title: "Kanji",
content: KanjiSearch()
),
Page(
title: "Memorization",
content: Container()
),
Page(
title: "Settings",
content: Container()
),
];

View File

@ -7,7 +7,13 @@ Widget searchForKanji(String kanji) {
return FutureBuilder(
future: jisho.searchForKanji(kanji),
builder: (BuildContext context, AsyncSnapshot<jisho.KanjiResult> snapshot) {
return KanjiResultCard(snapshot.data);
if (snapshot.hasData) {
return KanjiResultCard(snapshot.data);
} else if (snapshot.hasError) {
throw 'ASYNC ERROR';
} else {
return CircularProgressIndicator();
}
}
);
}