Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search bar #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
67 changes: 52 additions & 15 deletions lib/screens/plant_list.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
Expand All @@ -8,14 +9,26 @@ import 'package:water_me/models/plant_model.dart';
import 'package:water_me/screens/plant_edit.dart';
import 'package:water_me/screens/plant_list_entry.dart';
import 'package:water_me/theme.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:package_info_plus/package_info_plus.dart';

import '../main.dart';
import '../models/app_model.dart';

class MyPlants extends StatelessWidget {
const MyPlants({super.key});
class MyPlants extends StatefulWidget {
MyPlants({super.key});

@override
State<MyPlants> createState() => _MyPlantsState();
}

class _MyPlantsState extends State<MyPlants> {
String _search = "";

@override
void initState() {
super.initState();
_search = "";
}

Widget emptyList(BuildContext context) => Container(
height: MediaQuery.of(context).size.height,
Expand All @@ -38,27 +51,47 @@ class MyPlants extends StatelessWidget {
))
]));

Widget list(BuildContext context, AppModel m) => Container(
margin: const EdgeInsets.only(top: 0.0),
// decopration: BoxDecoration(color: Color.fromRGBO(58, 66, 86, 1.0)),
child: ListView.builder(
Widget list(BuildContext context, AppModel m) => ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: m.plants.length,
itemBuilder: (BuildContext context, int index) {
itemCount: m.plants.length + 1,
itemBuilder: (BuildContext context, int indexReal) {
if(indexReal == 0) {
return Padding(
padding: const EdgeInsets.only(left: 30.0, right: 30.0),
child: TextFormField(
onChanged: (v) {
setState(() {
_search = v;
});
},
style: const TextStyle(color: Colors.white),
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter a search term',
),
));
}

var index = indexReal - 1;
return ChangeNotifierProvider.value(
value: m.plants[index],
builder: (c, child) {
var last = index == m.plants.length - 1;
return PlantListEntry(lastEntry: last);
return Visibility(
child: PlantListEntry(lastEntry: last),
visible: m.plants[index].plantName
.toLowerCase()
.contains(_search));
});
},
));
);

AppBar appBar(BuildContext context) => AppBar(
elevation: 0.1,
backgroundColor: c1,
title: const Text("Plants"),
foregroundColor: Colors.white,
title: const Text("Plants", style: TextStyle(color: Colors.white)),
actions: <Widget>[
PopupMenuButton(
icon: const Icon(Icons.add),
Expand Down Expand Up @@ -125,7 +158,8 @@ class MyPlants extends StatelessWidget {
text: "Water-Me is built by abertschi.\n\n",
),
TextSpan(
style: const TextStyle(color: Colors.black,
style: const TextStyle(
color: Colors.black,
decoration: TextDecoration.underline),
text: "https://abertschi.ch\n\n",
recognizer: TapGestureRecognizer()
Expand All @@ -139,7 +173,8 @@ class MyPlants extends StatelessWidget {
text: "version ${packageInfo.version}",
recognizer: TapGestureRecognizer()
..onTap = () async {
const url = 'https://github.com/abertschi/water-me/blob/master/CHANGELOG';
const url =
'https://github.com/abertschi/water-me/blob/master/CHANGELOG';
await launchUrlString(url);
},
),
Expand Down Expand Up @@ -217,7 +252,9 @@ class MyPlants extends StatelessWidget {
appBar: appBar(context),
body: Consumer<AppModel>(
builder: (BuildContext context, AppModel m, Widget? child) {
return m.plants.isEmpty ? emptyList(context) : list(context, m);
return m.plants.isEmpty
? emptyList(context)
: list(context, m);
}));
}
}
1 change: 0 additions & 1 deletion lib/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ final appTheme = ThemeData(
fontFamily: 'Raleway',
colorScheme: ColorScheme.fromSwatch(
primarySwatch: materialColor,
primaryColorDark: c1,
accentColor: c1,
backgroundColor: c1,
errorColor: Colors.white,
Expand Down