Journal Search
This commit is contained in:
@@ -39,7 +39,9 @@ class _JournalPageState extends State<JournalPage>{
|
||||
super.dispose();
|
||||
refreshStream?.close();
|
||||
}
|
||||
|
||||
bool searching =false;
|
||||
TextEditingController searchController = TextEditingController();
|
||||
FocusNode _focus = FocusNode();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -52,7 +54,41 @@ class _JournalPageState extends State<JournalPage>{
|
||||
label: Text("New Entry"),
|
||||
icon: Icon(Icons.add)),
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
title: (searching)
|
||||
? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onChanged: (text) {
|
||||
setState(() {});
|
||||
},
|
||||
controller: searchController,
|
||||
focusNode: _focus,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
searching = false;
|
||||
searchController.clear();
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
child: Icon(Icons.cancel),
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
) :
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
@@ -80,6 +116,13 @@ class _JournalPageState extends State<JournalPage>{
|
||||
|
||||
});
|
||||
},child: Container(margin:EdgeInsets.all(8),child: Icon(Icons.cancel))),
|
||||
InkWell(onTap:(){
|
||||
searching=true;
|
||||
searchController.clear();
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},child: Container(margin:EdgeInsets.all(8),child: Icon(Icons.search))),
|
||||
if(!selecting)InkWell(onTap:(){setState(() {
|
||||
|
||||
});},child: Container(margin: EdgeInsets.all(8), child: Icon(Icons.refresh),))
|
||||
@@ -97,7 +140,20 @@ class _JournalPageState extends State<JournalPage>{
|
||||
int charCount = '\n'.allMatches(User.journal[index].description ?? '').length * 50;
|
||||
charCount +=(User.journal[index].description ?? '').length;
|
||||
int maxCharCount = 100;
|
||||
return Container(
|
||||
|
||||
bool matchesSearch = false;
|
||||
if(searching && searchController.text.isNotEmpty){
|
||||
if(User.journal[index].title != null && User.journal[index].title!.toLowerCase().contains(searchController.text.toLowerCase())){
|
||||
matchesSearch = true;
|
||||
}
|
||||
if((User.journal[index].description ?? '').toLowerCase().contains(searchController.text.toLowerCase())){
|
||||
matchesSearch=true;
|
||||
}
|
||||
}else{
|
||||
matchesSearch =true;
|
||||
}
|
||||
|
||||
return (matchesSearch) ? Container(
|
||||
child: InkWell(
|
||||
onTap: (){
|
||||
if(selecting){
|
||||
@@ -192,7 +248,7 @@ class _JournalPageState extends State<JournalPage>{
|
||||
},child: Container(margin:EdgeInsets.all(8),child: FaIcon(FontAwesomeIcons.edit)))
|
||||
],
|
||||
),
|
||||
));
|
||||
)) : Container();
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user