diff --git a/lib/database.dart b/lib/database.dart index b33a0e9..7c0500a 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -13,7 +13,7 @@ class Wolle extends Table { IntColumn get id => integer().autoIncrement()(); TextColumn get manufacture => text()(); TextColumn get title => text()(); - IntColumn get color => integer()(); + TextColumn get color => text().withLength(min: 7, max: 7)(); } class TempRange extends Table { diff --git a/lib/database.g.dart b/lib/database.g.dart index 7a7b1fa..8301640 100644 --- a/lib/database.g.dart +++ b/lib/database.g.dart @@ -30,9 +30,12 @@ class $WolleTable extends Wolle with TableInfo<$WolleTable, WolleData> { type: DriftSqlType.string, requiredDuringInsert: true); static const VerificationMeta _colorMeta = const VerificationMeta('color'); @override - late final GeneratedColumn color = GeneratedColumn( + late final GeneratedColumn color = GeneratedColumn( 'color', aliasedName, false, - type: DriftSqlType.int, requiredDuringInsert: true); + additionalChecks: + GeneratedColumn.checkTextLength(minTextLength: 7, maxTextLength: 7), + type: DriftSqlType.string, + requiredDuringInsert: true); @override List get $columns => [id, manufacture, title, color]; @override @@ -84,7 +87,7 @@ class $WolleTable extends Wolle with TableInfo<$WolleTable, WolleData> { title: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}title'])!, color: attachedDatabase.typeMapping - .read(DriftSqlType.int, data['${effectivePrefix}color'])!, + .read(DriftSqlType.string, data['${effectivePrefix}color'])!, ); } @@ -98,7 +101,7 @@ class WolleData extends DataClass implements Insertable { final int id; final String manufacture; final String title; - final int color; + final String color; const WolleData( {required this.id, required this.manufacture, @@ -110,7 +113,7 @@ class WolleData extends DataClass implements Insertable { map['id'] = Variable(id); map['manufacture'] = Variable(manufacture); map['title'] = Variable(title); - map['color'] = Variable(color); + map['color'] = Variable(color); return map; } @@ -130,7 +133,7 @@ class WolleData extends DataClass implements Insertable { id: serializer.fromJson(json['id']), manufacture: serializer.fromJson(json['manufacture']), title: serializer.fromJson(json['title']), - color: serializer.fromJson(json['color']), + color: serializer.fromJson(json['color']), ); } @override @@ -140,12 +143,12 @@ class WolleData extends DataClass implements Insertable { 'id': serializer.toJson(id), 'manufacture': serializer.toJson(manufacture), 'title': serializer.toJson(title), - 'color': serializer.toJson(color), + 'color': serializer.toJson(color), }; } WolleData copyWith( - {int? id, String? manufacture, String? title, int? color}) => + {int? id, String? manufacture, String? title, String? color}) => WolleData( id: id ?? this.id, manufacture: manufacture ?? this.manufacture, @@ -179,7 +182,7 @@ class WolleCompanion extends UpdateCompanion { final Value id; final Value manufacture; final Value title; - final Value color; + final Value color; const WolleCompanion({ this.id = const Value.absent(), this.manufacture = const Value.absent(), @@ -190,7 +193,7 @@ class WolleCompanion extends UpdateCompanion { this.id = const Value.absent(), required String manufacture, required String title, - required int color, + required String color, }) : manufacture = Value(manufacture), title = Value(title), color = Value(color); @@ -198,7 +201,7 @@ class WolleCompanion extends UpdateCompanion { Expression? id, Expression? manufacture, Expression? title, - Expression? color, + Expression? color, }) { return RawValuesInsertable({ if (id != null) 'id': id, @@ -212,7 +215,7 @@ class WolleCompanion extends UpdateCompanion { {Value? id, Value? manufacture, Value? title, - Value? color}) { + Value? color}) { return WolleCompanion( id: id ?? this.id, manufacture: manufacture ?? this.manufacture, @@ -234,7 +237,7 @@ class WolleCompanion extends UpdateCompanion { map['title'] = Variable(title.value); } if (color.present) { - map['color'] = Variable(color.value); + map['color'] = Variable(color.value); } return map; } diff --git a/lib/db_test.dart b/lib/db_test.dart index 5933da3..14fe924 100644 --- a/lib/db_test.dart +++ b/lib/db_test.dart @@ -1,20 +1,16 @@ import 'package:drift/drift.dart'; import 'package:flutter/material.dart'; -import 'package:hexcolor/hexcolor.dart'; import 'package:provider/provider.dart'; import 'package:temperaturdecke/database.dart'; -void addWool(BuildContext context, String title, String? manufacture, - Color color) async { +void addWool(BuildContext context) async { try { AppDatabase db = Provider.of(context, listen: false); - print("adding wool"); - db.into(db.wolle).insert(WolleCompanion.insert( - title: title, - color: color.value, - manufacture: manufacture ?? "none", + title: 'Kakapo', + color: '#00FF05', + manufacture: 'test', )); } catch (e) { // Fehlerbehandlung hier @@ -31,13 +27,3 @@ void removeWool(BuildContext context, int dId) async { print('Fehler beim Einfügen: $e'); } } - -void deleteEverything(BuildContext context) async { - AppDatabase db = Provider.of(context, listen: false); - // you only need this if you've manually enabled foreign keys - // await customStatement('PRAGMA foreign_keys = OFF'); - for (final table in db.allTables) { - await db.delete(table).go(); - } - ; -} diff --git a/lib/screens/add_wool_modal.dart b/lib/screens/add_wool_modal.dart index b278488..d203934 100644 --- a/lib/screens/add_wool_modal.dart +++ b/lib/screens/add_wool_modal.dart @@ -1,93 +1,32 @@ -import 'package:flex_color_picker/flex_color_picker.dart'; import 'package:flutter/material.dart'; -import 'package:hexcolor/hexcolor.dart'; -import 'package:temperaturdecke/db_test.dart'; +import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import 'package:temperaturdecke/widgets/modal_wrapper.dart'; class AddWoolModal extends StatelessWidget { AddWoolModal({super.key}); - Color selectedColor = Colors.white; - String title = ""; - String manufacture = ""; + String selectedColor = "#FFFFFF"; void setSelectedColor(Color color) { - selectedColor = color; + selectedColor = colorToHex(color); } @override Widget build(BuildContext context) { return ModalWrapper( Column( - crossAxisAlignment: CrossAxisAlignment.start, children: [ - SizedBox( - height: 15, - ), - Text( - "Randdaten", - textAlign: TextAlign.start, - style: Theme.of(context).textTheme.headlineSmall, - ), - SizedBox( - height: 10, - ), - TextField( - onChanged: (value) => {title = value}, - decoration: InputDecoration( - border: OutlineInputBorder(), - labelText: 'Name', - ), - ), + TextField(), + TextField(), SizedBox( height: 25, ), - TextField( - onChanged: (value) => {manufacture = value}, - decoration: InputDecoration( - border: OutlineInputBorder(), - labelText: 'Marke', - ), - ), - SizedBox( - height: 30, - ), - Text( - "Farbe", - textAlign: TextAlign.start, - style: Theme.of(context).textTheme.headlineSmall, - ), - SizedBox( - height: 10, - ), ColorPicker( - spacing: 8, - padding: EdgeInsets.all(0), - borderRadius: 10, - onColorChanged: (value) => setSelectedColor(value), - enableShadesSelection: false, - enableTonalPalette: true, - tonalColorSameSize: true, - pickersEnabled: {ColorPickerType.accent: false}, - tonalSubheading: Divider(), - ), - SizedBox( - height: 25, - ), - Align( - alignment: Alignment.centerRight, - child: FilledButton( - onPressed: () => addWool( - context, - title, - manufacture, - selectedColor, - ), - child: Text( - "Hinzufügen", - style: TextStyle(fontSize: 16), - ), - ), + displayThumbColor: false, + colorPickerWidth: 200, + enableAlpha: false, + pickerColor: Colors.black, + onColorChanged: setSelectedColor, ) ], ), diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 8a199e8..70453b3 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -22,8 +22,6 @@ class AccentColorExample extends StatelessWidget { @override Widget build(BuildContext context) { - return FilledButton( - child: Text("Delete all"), - onPressed: () => {deleteEverything(context)}); + return Placeholder(); } } diff --git a/lib/screens/wool.dart b/lib/screens/wool.dart index a8c0a29..fcdb26c 100644 --- a/lib/screens/wool.dart +++ b/lib/screens/wool.dart @@ -79,7 +79,7 @@ class WoolScreen extends StatelessWidget { index, snapshot.data[index].manufacture, snapshot.data[index].title, - Color(snapshot.data[index].color), + snapshot.data[index].color, ), const SizedBox( height: 15, diff --git a/lib/widgets/cards/wool_card.dart b/lib/widgets/cards/wool_card.dart index 1eedd77..c1f1881 100644 --- a/lib/widgets/cards/wool_card.dart +++ b/lib/widgets/cards/wool_card.dart @@ -9,7 +9,7 @@ class Woolcard extends StatelessWidget { int id; String manufacture; String title; - Color color; + String color; @override Widget build(BuildContext context) { return CustomCard(Row( @@ -21,7 +21,7 @@ class Woolcard extends StatelessWidget { Container( height: 70, width: 30, - color: color, + color: HexColor(color), ), Padding( padding: const EdgeInsets.all(10.0), diff --git a/lib/widgets/modal_wrapper.dart b/lib/widgets/modal_wrapper.dart index a71319d..170ff7a 100644 --- a/lib/widgets/modal_wrapper.dart +++ b/lib/widgets/modal_wrapper.dart @@ -17,7 +17,7 @@ class ModalWrapper extends StatelessWidget { width: 750, height: MediaQuery.of(context).size.height - 100, child: Padding( - padding: EdgeInsets.symmetric(horizontal: 25, vertical: 0), + padding: EdgeInsets.symmetric(horizontal: 25, vertical: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/pubspec.lock b/pubspec.lock index 62bc216..7737e2d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -265,27 +265,19 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - flex_color_picker: - dependency: "direct main" - description: - name: flex_color_picker - sha256: "5c846437069fb7afdd7ade6bf37e628a71d2ab0787095ddcb1253bf9345d5f3a" - url: "https://pub.dev" - source: hosted - version: "3.4.1" - flex_seed_scheme: - dependency: transitive - description: - name: flex_seed_scheme - sha256: "4cee2f1d07259f77e8b36f4ec5f35499d19e74e17c7dce5b819554914082bc01" - url: "https://pub.dev" - source: hosted - version: "1.5.0" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_colorpicker: + dependency: "direct main" + description: + name: flutter_colorpicker + sha256: "969de5f6f9e2a570ac660fb7b501551451ea2a1ab9e2097e89475f60e07816ea" + url: "https://pub.dev" + source: hosted + version: "1.1.0" flutter_lints: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 08cc1c4..0f920b0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,7 +35,7 @@ dependencies: shimmer: - flex_color_picker: + flutter_colorpicker: hexcolor: