-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from aeri/f-droid
FOSS transition
- Loading branch information
Showing
21 changed files
with
1,135 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule ".flutter"] | ||
path = .flutter | ||
url = https://github.com/flutter/flutter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'care.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Care { | ||
int id = 0; | ||
String name; | ||
int cycles = 0; | ||
DateTime? effected; | ||
|
||
Care( | ||
{required this.name, | ||
required this.cycles, | ||
required this.effected, | ||
required this.id}); | ||
|
||
factory Care.fromJson(Map<String, dynamic> json) => _$CareFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$CareToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'dart:convert'; | ||
import 'package:florae/data/plant.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
||
class Garden { | ||
late final SharedPreferences store; | ||
|
||
Garden(this.store); | ||
|
||
static Future<Garden> load() async { | ||
var store = await SharedPreferences.getInstance(); | ||
|
||
await store.reload(); | ||
|
||
return (Garden(store)); | ||
} | ||
|
||
Future<List<Plant>> getAllPlants() async { | ||
List<Plant> allPlants = []; | ||
var rawPlants = store.getString("plants"); | ||
if (rawPlants != null) { | ||
Iterable l = json.decode(rawPlants); | ||
allPlants = List<Plant>.from(l.map((model) => Plant.fromJson(model))); | ||
} | ||
return allPlants; | ||
} | ||
|
||
// Returns true if update | ||
// Return false if create | ||
Future<bool> addOrUpdatePlant(Plant plant) async { | ||
List<Plant> allPlants = await getAllPlants(); | ||
bool status; | ||
|
||
var plantIndex = | ||
allPlants.indexWhere((element) => element.name == plant.name); | ||
if (plantIndex == -1) { | ||
allPlants.add(plant); | ||
status = false; | ||
} else { | ||
allPlants[allPlants.indexWhere((element) => element.name == plant.name)] = | ||
plant; | ||
status = true; | ||
} | ||
String jsonPlants = jsonEncode(allPlants); | ||
await store.setString("plants", jsonPlants); | ||
|
||
return status; | ||
} | ||
|
||
Future<bool> deletePlant(Plant plant) async { | ||
List<Plant> allPlants = await getAllPlants(); | ||
|
||
var plantIndex = | ||
allPlants.indexWhere((element) => element.name == plant.name); | ||
if (plantIndex != -1) { | ||
allPlants.removeAt(plantIndex); | ||
|
||
String jsonPlants = jsonEncode(allPlants); | ||
await store.setString("plants", jsonPlants); | ||
|
||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
Future<bool> updatePlant(Plant plant) async { | ||
List<Plant> allPlants = await getAllPlants(); | ||
|
||
var plantIndex = | ||
allPlants.indexWhere((element) => element.name == plant.name); | ||
if (plantIndex != -1) { | ||
allPlants[allPlants.indexWhere((element) => element.name == plant.name)] = | ||
plant; | ||
|
||
String jsonPlants = jsonEncode(allPlants); | ||
await store.setString("plants", jsonPlants); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,28 @@ | ||
import 'package:objectbox/objectbox.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'care.dart'; | ||
|
||
@Entity() | ||
class Care { | ||
int id = 0; | ||
String name; | ||
int cycles = 0; | ||
@Property(type: PropertyType.date) | ||
DateTime? effected; | ||
|
||
Care({required this.name, required this.cycles, required this.effected}); | ||
|
||
factory Care.fromJson(Map<String, dynamic> json) => Care( | ||
cycles: json["cycles"], effected: json["effected"], name: json["name"]); | ||
part 'plant.g.dart'; | ||
|
||
Map<String, dynamic> toJson() => | ||
{"cycles": cycles, "effected": effected, "name": name}; | ||
} | ||
|
||
@Entity() | ||
@JsonSerializable(explicitToJson: true) | ||
class Plant { | ||
int id = 0; | ||
String name; | ||
String? location; | ||
String description; | ||
@Property(type: PropertyType.date) | ||
DateTime createdAt; | ||
String? picture; | ||
|
||
final cares = ToMany<Care>(); | ||
List<Care> cares = []; | ||
|
||
Plant( | ||
{required this.name, | ||
this.id = 0, | ||
this.location, | ||
this.description = "", | ||
required this.createdAt, | ||
this.picture}); | ||
this.picture, | ||
required this.cares}); | ||
|
||
factory Plant.fromJson(Map<String, dynamic> json) => Plant( | ||
name: json["name"], | ||
location: json["location"], | ||
description: json["description"], | ||
createdAt: json["createdAt"], | ||
picture: json["picture"], | ||
); | ||
factory Plant.fromJson(Map<String, dynamic> json) => _$PlantFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"name": name, | ||
"location": location, | ||
"description": description, | ||
"createdAt": createdAt, | ||
"picture": picture, | ||
}; | ||
Map<String, dynamic> toJson() => _$PlantToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.