Skip to content

Commit

Permalink
pretty much all done.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul74 committed Mar 14, 2021
1 parent 769e367 commit a2645e0
Showing 14 changed files with 150 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_cropper","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_cropper-1.4.0\\\\","dependencies":[]},{"name":"image_picker","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.7.2+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+2\\\\","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-2.0.0\\\\","dependencies":[]},{"name":"image_cropper","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_cropper-1.4.0\\\\","dependencies":[]},{"name":"image_picker","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.7.2+1\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+2\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.0\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+2\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.0.0\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.0\\\\","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_cropper","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2021-03-13 09:46:41.350747","version":"2.1.0-11.0.pre.145"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"image_cropper","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_cropper-1.4.0\\\\","dependencies":[]},{"name":"image_picker","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.7.2+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+2\\\\","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\flutter_plugin_android_lifecycle-2.0.0\\\\","dependencies":[]},{"name":"image_cropper","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_cropper-1.4.0\\\\","dependencies":[]},{"name":"image_picker","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\image_picker-0.7.2+1\\\\","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"path_provider","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-2.0.1\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+2\\\\","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_macos-2.0.0\\\\","dependencies":[]},{"name":"sqflite","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\sqflite-2.0.0+2\\\\","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_linux-2.0.0\\\\","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\src\\\\flutter\\\\.pub-cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider_windows-2.0.0\\\\","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"image_cropper","dependencies":[]},{"name":"image_picker","dependencies":["flutter_plugin_android_lifecycle"]},{"name":"path_provider","dependencies":["path_provider_macos","path_provider_linux","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2021-03-14 18:02:52.598260","version":"2.0.2"}
6 changes: 3 additions & 3 deletions .packages
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#
# For more info see: https://dart.dev/go/dot-packages-deprecation
#
# Generated by pub on 2021-03-13 09:32:23.499971.
# Generated by pub on 2021-03-13 20:02:06.664672.
async:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.5.0/lib/
boolean_selector:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/
characters:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/
@@ -16,7 +16,7 @@ ffi:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.0.0/lib/
file:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/file-6.1.0/lib/
flutter:file:///C:/src/flutter/packages/flutter/lib/
flutter_plugin_android_lifecycle:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_plugin_android_lifecycle-2.0.0/lib/
flutter_slidable:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_slidable-0.5.7/lib/
flutter_slidable:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_slidable-0.6.0-nullsafety.0/lib/
flutter_test:file:///C:/src/flutter/packages/flutter_test/lib/
http:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.13.0/lib/
http_parser:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-4.0.0/lib/
@@ -38,7 +38,7 @@ plugin_platform_interface:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.
process:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/process-4.1.0/lib/
provider:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/provider-5.0.0/lib/
sky_engine:file:///C:/src/flutter/bin/cache/pkg/sky_engine/lib/
source_span:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.8.1/lib/
source_span:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.8.0/lib/
sqflite:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-2.0.0+2/lib/
sqflite_common:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite_common-2.0.0+2/lib/
stack_trace:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.10.0/lib/
5 changes: 4 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
//Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.myrecipes_app"
minSdkVersion 21
targetSdkVersion 29
@@ -46,6 +46,9 @@ android {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
// adding these 2 lines, if not the release apk won't run
shrinkResources false
minifyEnabled false
}
}
}
57 changes: 4 additions & 53 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:myrecipes_app/screens/recipes_entry.dart';
import 'package:myrecipes_app/screens/recipes_list.dart';
import 'package:path_provider/path_provider.dart';
import 'common/utils.dart' as utils;
import 'screens/recipes.dart';
import 'package:myrecipes_app/models/recipes_model.dart';
import 'package:provider/provider.dart';


//preferisco gestire le pagine con il semplice navigator, così ho animazioni automatiche e appbar più facili da fare per ogni pagina.
// vedi https://github.com/flutter/samples/tree/master/provider_shopper
class app extends StatelessWidget {
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@@ -67,7 +61,7 @@ class app extends StatelessWidget {

),

/* ORIGINALE FUNZIONANTE
/* WORKING ORIGINAL
home: Scaffold(
appBar: AppBar(
title: Text("myrecipes"),
@@ -76,7 +70,7 @@ class app extends StatelessWidget {
),
*/

// PROVO CON LE ROUTES
//ROUTES
initialRoute: '/list',
routes: {
// '/': (context) => MyLogin(),
@@ -85,49 +79,6 @@ class app extends StatelessWidget {
},
//


);
}
}




//segue come avevo fatto io, soprattutto per mettere il + nella appbar. ma è troppo complicato e ci sono cose inutili.
/*
class Notebook extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider.value(
value: recipesModel,
child:
MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("myapp"),
actions: <Widget>[
//if (recipesModel.stackIndex==0) //da implementare il funzionamento, non si aggiorna la appbar
Consumer<RecipesModel>(
builder:(context,recipesModel,child) {return
IndexedStack(index: recipesModel.stackIndex,children:[
IconButton(
icon: const Icon(Icons.add),
onPressed: () {
print("add recipe");
recipesModel.recipeBeingEdited = Recipe();
recipesModel.setStackIndex(1);
},
),
Container() //blanck container because I don't need buttons on recipe edit/new
]);
},
),
],
),
body: Recipes(),
),
),);
}
}*/
}
6 changes: 3 additions & 3 deletions lib/common/utils.dart
Original file line number Diff line number Diff line change
@@ -14,9 +14,9 @@ bool isNumeric(String s) {

// class for mantaining state between tabs for forms validation in recipes_entry
class KeepAliveWrapper extends StatefulWidget {
final Widget child;
final Widget? child;

const KeepAliveWrapper({Key key, this.child}) : super(key: key);
const KeepAliveWrapper({Key? key, this.child}) : super(key: key);

@override
__KeepAliveWrapperState createState() => __KeepAliveWrapperState();
@@ -27,7 +27,7 @@ class __KeepAliveWrapperState extends State<KeepAliveWrapper>
@override
Widget build(BuildContext context) {
super.build(context);
return widget.child;
return widget.child!;
}

@override
76 changes: 42 additions & 34 deletions lib/db/recipes_db_worker.dart
Original file line number Diff line number Diff line change
@@ -3,15 +3,16 @@ import 'package:sqflite/sqflite.dart';
import '../common/utils.dart' as utils;
import '../models/recipes_model.dart';
import '../models/categories_model.dart';
import 'dart:async';

class RecipesDBworker {

RecipesDBworker._();
static final RecipesDBworker recipesDBworker = RecipesDBworker._();

Database _db;
static Database? _db;

Future<Database> _getDB() async {
Future<Database?> _getDB() async {
if(_db==null){
String path = join(utils.docsDir.path, "recipes.db");
_db = await openDatabase(path, version: 1,
@@ -35,19 +36,19 @@ class RecipesDBworker {
"category TEXT)");

//procedura per creare delle categorie di default nella tabella categories
int id0 = await inDB.rawInsert(
await inDB.rawInsert(
'INSERT INTO categories (id, category) VALUES (0, "~ ALL RECIPES ~")');
int id1 = await inDB.rawInsert(
await inDB.rawInsert(
'INSERT INTO categories (id, category) VALUES (1, "APPETIZERS")');
int id2 = await inDB.rawInsert(
await inDB.rawInsert(
'INSERT INTO categories (id, category) VALUES (2, "STARTERS")');
int id3 = await inDB.rawInsert(
await inDB.rawInsert(
'INSERT INTO categories (id, category) VALUES (3, "MAIN DISHES")');
int id4 = await inDB.rawInsert(
await inDB.rawInsert(
'INSERT INTO categories (id, category) VALUES (4, "SALADS")');
int id5 = await inDB.rawInsert(
await inDB.rawInsert(
'INSERT INTO categories (id, category) VALUES (5, "SIDE DISHES")');
int id6 = await inDB.rawInsert(
await inDB.rawInsert(
'INSERT INTO categories (id, category) VALUES (6, "DESSERTS")');
//

@@ -91,48 +92,50 @@ class RecipesDBworker {
}

Future create(Recipe inRecipe) async {
Database db = await _getDB();
var val = await db.rawQuery("SELECT MAX(id) + 1 AS id FROM recipes");
int id = val.first["id"];
//Database db = await (_getDB() as FutureOr<Database>);
Database? db = await _getDB();
var val = await db?.rawQuery("SELECT MAX(id) + 1 AS id FROM recipes");
int? id = val?.first["id"] as int?;
if (id==null){
id = 1;
}
return await db.rawInsert(
return await db?.rawInsert(
"INSERT INTO recipes (id, idCat, title, image, fav, notes, minutes, difficulty, persons, ingredients, preparation) "
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
[id, inRecipe.idCat, inRecipe.title, inRecipe.image, inRecipe.fav, inRecipe.notes, inRecipe.minutes, inRecipe.difficulty, inRecipe.persons, inRecipe.ingredients, inRecipe.preparation]//, inRecipe.color]
);
}

Future<Recipe> get(int inID) async {
Database db = await _getDB();
var rec = await db.query("recipes", where: "id = ?", whereArgs: [inID]);
return recipeFromMap(rec.first);
Future<Recipe> get(int? inID) async {
//Database db = await (_getDB() as FutureOr<Database>);
Database? db = await _getDB();
var rec = await db?.query("recipes", where: "id = ?", whereArgs: [inID]);
return recipeFromMap(rec!.first);
}

Future<List> getAll(int idcat, String order) async {
Database db = await _getDB();
var recs;
Future<List?> getAll(int idcat, String order) async {
Database? db = await _getDB();
late var recs;
//var recs = await db.query("recipes");
if (idcat == 0) {
if (order=="AZ") {
//recs = await db.query("recipes"); //IDcat == 0 means all recipes so retrieve all
recs = await db.rawQuery('SELECT * FROM "recipes" ORDER BY title ASC'); //IDcat == 0 means all recipes so retrieve all
recs = await db!.rawQuery('SELECT * FROM "recipes" ORDER BY title ASC'); //IDcat == 0 means all recipes so retrieve all
} else if (order == "ZA") {
recs = await db.rawQuery('SELECT * FROM "recipes" ORDER BY title DESC'); //IDcat == 0 means all recipes so retrieve all
recs = await db!.rawQuery('SELECT * FROM "recipes" ORDER BY title DESC'); //IDcat == 0 means all recipes so retrieve all
} else {
recs = await db.rawQuery('SELECT * FROM "recipes" ORDER BY id DESC'); //IDcat == 0 means all recipes so retrieve all
recs = await db!.rawQuery('SELECT * FROM "recipes" ORDER BY id DESC'); //IDcat == 0 means all recipes so retrieve all
}
}

if (idcat != 0) {
//recs = await db.query("recipes", where: "idCat = ?", whereArgs: [idcat]);
if (order=="AZ") {
recs = await db.rawQuery("SELECT * FROM recipes WHERE idCat = ? ORDER BY title ASC", [idcat]);
recs = await db!.rawQuery("SELECT * FROM recipes WHERE idCat = ? ORDER BY title ASC", [idcat]);
} else if (order == "ZA") {
recs = await db.rawQuery("SELECT * FROM recipes WHERE idCat = ? ORDER BY title DESC", [idcat]);
recs = await db!.rawQuery("SELECT * FROM recipes WHERE idCat = ? ORDER BY title DESC", [idcat]);
} else {
recs = await db.rawQuery("SELECT * FROM recipes WHERE idCat = ? ORDER BY id DESC", [idcat]);
recs = await db!.rawQuery("SELECT * FROM recipes WHERE idCat = ? ORDER BY id DESC", [idcat]);
}
}

@@ -142,13 +145,15 @@ class RecipesDBworker {


Future update(Recipe inRecipe) async {
Database db = await _getDB();
return await db.update("recipes", recipeToMap(inRecipe), where: "id = ?", whereArgs: [inRecipe.id]);
//Database db = await (_getDB() as FutureOr<Database>);
Database? db = await _getDB();
return await db?.update("recipes", recipeToMap(inRecipe), where: "id = ?", whereArgs: [inRecipe.id]);
}

Future delete(int inID) async {
Database db = await _getDB();
return await db.delete("recipes", where: "id = ?", whereArgs: [inID]);
Future delete(int? inID) async {
//Database db = await (_getDB() as FutureOr<Database>);
Database? db = await _getDB();
return await db?.delete("recipes", where: "id = ?", whereArgs: [inID]);
}


@@ -170,10 +175,13 @@ class RecipesDBworker {


Future<List> getAllcategories() async {
Database db = await _getDB();
var categs = await db.query("categories");
//Database db = await (_getDB() as FutureOr<Database>);
Database? db = await _getDB();
var categs = await db?.query("categories");
//print("db $db");
//var categs = await db.rawQuery('SELECT * FROM "categories" ORDER BY "id"'); //this would work if I need ordering
var list = categs.isEmpty ? [] : categs.map((m) => categoryFromMap(m)).toList();
//var list = categs.isEmpty ? [] : categs.map((m) => categoryFromMap(m)).toList();
var list = categs!.map((m) => categoryFromMap(m)).toList();
return list;
}

11 changes: 3 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -7,14 +7,9 @@

import 'package:flutter/material.dart';
import 'dart:io';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:myrecipes_app/app.dart';
import 'package:path_provider/path_provider.dart';
import 'common/utils.dart' as utils;
import 'db/recipes_db_worker.dart';
import 'screens/recipes.dart';
import 'package:myrecipes_app/models/recipes_model.dart';
import 'package:myrecipes_app/models/categories_model.dart';
import 'package:path_provider/path_provider.dart';


void main() async {
@@ -23,7 +18,7 @@ void main() async {
//var docsDir = new Directory('/data/user/0/com.example.myrecipes_app/app_flutter'); //per l'ufficio
utils.docsDir = docsDir;
//categoriesModel.loadData(RecipesDBworker.recipesDBworker); //provo a metterlo in recipes.dat devo caricare la lista delle categorie
runApp(app());
print(docsDir);
runApp(App());
//print(docsDir);
//runApp(MyApp());
}
Loading

0 comments on commit a2645e0

Please sign in to comment.