Add FilamentModel with all properties and refactor notes as optional
This commit is contained in:
10
lib/configs/environment.dart
Normal file
10
lib/configs/environment.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
class Environment {
|
||||
static const String appwritePublicEndpoint =
|
||||
'https://appwrite.joshihomeserver.ipv64.net/v1';
|
||||
static const String appwriteProjectId = '6894f2b0001f127bab72';
|
||||
static const String appwriteProjectName = 'Flutter Projects';
|
||||
static const String appwriteRealtimeCollectionId = '696dd4dd0032ff13e5b4';
|
||||
static const String appwriteDatabaseId = '68a22ef90021b90f0f43';
|
||||
static const String appwriteUserEMail = 'wei@a1.net';
|
||||
static const String appwritePasswd = '123456789';
|
||||
}
|
||||
105
lib/controllers/home_controller.dart
Normal file
105
lib/controllers/home_controller.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../models/home_model.dart';
|
||||
import '../services/appwrite_service.dart';
|
||||
import '../widgets/add_weight_dialog.dart';
|
||||
|
||||
class HomeController extends GetxController {
|
||||
final isloading = false.obs;
|
||||
final List<WeightModel> weights = <WeightModel>[].obs;
|
||||
final appwriteService = AppwriteService();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
_loadDataList();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {}
|
||||
|
||||
@override
|
||||
void onClose() {}
|
||||
|
||||
void _loadDataList() async {
|
||||
isloading.value = true;
|
||||
if (weights.isNotEmpty) {
|
||||
weights.clear();
|
||||
}
|
||||
final loggedIn = await appwriteService.login();
|
||||
if (!loggedIn) {
|
||||
print('Login fehlgeschlagen – Daten können nicht geladen werden.');
|
||||
isloading.value = false;
|
||||
return;
|
||||
}
|
||||
final documents = await appwriteService.getDocumentsFromCollection();
|
||||
if (documents.isEmpty) {
|
||||
print('Keine Dokumente gefunden.');
|
||||
} else {
|
||||
print('${documents.length} Einträge geladen.');
|
||||
weights.assignAll(documents.map((doc) => WeightModel.fromJson(doc.data)));
|
||||
}
|
||||
isloading.value = false;
|
||||
update();
|
||||
}
|
||||
|
||||
void addWeightEntry(WeightModel entry) {
|
||||
weights.add(entry);
|
||||
var map = WeightModel.toMapForAppwrite(entry);
|
||||
appwriteService.createDocumentInCollection(map);
|
||||
update();
|
||||
}
|
||||
|
||||
void editWeightEntry(WeightModel updated) {
|
||||
final idx = weights.indexWhere(
|
||||
(w) => w.documentId == updated.documentId && w.date == updated.date,
|
||||
);
|
||||
if (idx != -1) {
|
||||
weights[idx] = updated;
|
||||
var map = WeightModel.toMapForAppwrite(updated);
|
||||
appwriteService.updateDocumentInCollection(updated.documentId, map);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/// Gewicht des Eintrags unmittelbar VOR [date] einer Person.
|
||||
/// Wird für die weightChange-Berechnung beim Bearbeiten genutzt.
|
||||
double getPreviousWeight(String personName, DateTime date) {
|
||||
final before = weights
|
||||
.where((w) => w.name == personName && w.date.isBefore(date))
|
||||
.toList();
|
||||
if (before.isEmpty) return 0.0;
|
||||
before.sort((a, b) => b.date.compareTo(a.date));
|
||||
return before.first.weight;
|
||||
}
|
||||
|
||||
/// Gibt das zuletzt eingetragene Gewicht einer Person zurück.
|
||||
/// 0.0 wenn noch kein Eintrag existiert (wird als "erster Eintrag" behandelt).
|
||||
double getLastWeight(String personName) {
|
||||
final personEntries = weights.where((w) => w.name == personName).toList();
|
||||
if (personEntries.isEmpty) return 0.0;
|
||||
personEntries.sort((a, b) => b.date.compareTo(a.date));
|
||||
return personEntries.first.weight;
|
||||
}
|
||||
|
||||
void addWeight(String personName) {}
|
||||
|
||||
// ── Dialog-Logik ─────────────────────────────────────────────────────────
|
||||
|
||||
Future<void> openAddDialog(String personName, String userId) async {
|
||||
final entry = await AddWeightDialog.show(
|
||||
userId: userId,
|
||||
personName: personName,
|
||||
lastWeight: getLastWeight(personName),
|
||||
);
|
||||
if (entry != null) addWeightEntry(entry);
|
||||
}
|
||||
|
||||
Future<void> openEditDialog(WeightModel existing) async {
|
||||
final updated = await AddWeightDialog.showEdit(
|
||||
entry: existing,
|
||||
previousWeight: getPreviousWeight(existing.name, existing.date),
|
||||
);
|
||||
if (updated != null) editWeightEntry(updated);
|
||||
}
|
||||
}
|
||||
18
lib/helpers/sample_bindings.dart
Normal file
18
lib/helpers/sample_bindings.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../controllers/home_controller.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SampleBindings extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
// Define your dependencies here no permanent Binding
|
||||
Get.lazyPut<HomeController>(() => HomeController());
|
||||
|
||||
}
|
||||
}
|
||||
18
lib/helpers/samples_routes.dart
Normal file
18
lib/helpers/samples_routes.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../pages/home/home_view.dart';
|
||||
import 'sample_bindings.dart';
|
||||
|
||||
|
||||
class SampleRouts {
|
||||
static final sampleBindings = SampleBindings();
|
||||
static List<GetPage<dynamic>> samplePages = [
|
||||
|
||||
GetPage(
|
||||
name: HomePage.namedRoute,
|
||||
page: () => const HomePage(),
|
||||
binding: sampleBindings,
|
||||
),
|
||||
|
||||
];
|
||||
}
|
||||
28
lib/main.dart
Normal file
28
lib/main.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'helpers/samples_routes.dart';
|
||||
import 'pages/home/home_view.dart';
|
||||
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetMaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
||||
useMaterial3: true,
|
||||
),
|
||||
initialRoute: HomePage.namedRoute,
|
||||
getPages: SampleRouts.samplePages,
|
||||
);
|
||||
}
|
||||
}
|
||||
78
lib/models/filament_model.dart
Normal file
78
lib/models/filament_model.dart
Normal file
@@ -0,0 +1,78 @@
|
||||
class FilamentModel {
|
||||
final String documentId;
|
||||
final String name;
|
||||
final String type;
|
||||
final String color;
|
||||
final double weight;
|
||||
final double weightUsed;
|
||||
final double price;
|
||||
final String manufacture;
|
||||
final String purchaseDate;
|
||||
final String? notes;
|
||||
final int printingTemp;
|
||||
final int bedTemp;
|
||||
|
||||
FilamentModel({
|
||||
required this.documentId,
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.color,
|
||||
required this.weight,
|
||||
required this.weightUsed,
|
||||
required this.price,
|
||||
required this.manufacture,
|
||||
required this.purchaseDate,
|
||||
this.notes,
|
||||
required this.printingTemp,
|
||||
required this.bedTemp,
|
||||
});
|
||||
|
||||
static FilamentModel fromJson(Map<String, dynamic> json) {
|
||||
return FilamentModel(
|
||||
documentId: json['\$id'],
|
||||
name: json['name'],
|
||||
type: json['type'],
|
||||
color: json['color'],
|
||||
weight: (json['weight'] as num).toDouble(),
|
||||
weightUsed: (json['weightUsed'] as num).toDouble(),
|
||||
price: (json['price'] as num).toDouble(),
|
||||
manufacture: json['manufacture'],
|
||||
purchaseDate: json['purchaseDate'],
|
||||
notes: json['notes'] as String?,
|
||||
printingTemp: json['printingTemp'],
|
||||
bedTemp: json['bedTemp'],
|
||||
);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMapForAppwrite(FilamentModel filamentModel) {
|
||||
return {
|
||||
'name': filamentModel.name,
|
||||
'type': filamentModel.type,
|
||||
'color': filamentModel.color,
|
||||
'weight': filamentModel.weight,
|
||||
'weightUsed': filamentModel.weightUsed,
|
||||
'price': filamentModel.price,
|
||||
'manufacture': filamentModel.manufacture,
|
||||
'purchaseDate': filamentModel.purchaseDate,
|
||||
if (filamentModel.notes != null) 'notes': filamentModel.notes,
|
||||
'printingTemp': filamentModel.printingTemp,
|
||||
'bedTemp': filamentModel.bedTemp,
|
||||
};
|
||||
}
|
||||
|
||||
// An empty instance for initialization or default values
|
||||
static final empty = FilamentModel(
|
||||
documentId: '00',
|
||||
name: '',
|
||||
type: '',
|
||||
color: '',
|
||||
weight: 0.0,
|
||||
weightUsed: 0.0,
|
||||
price: 0.0,
|
||||
manufacture: '',
|
||||
purchaseDate: '',
|
||||
notes: null,
|
||||
printingTemp: 0,
|
||||
bedTemp: 0,
|
||||
);
|
||||
}
|
||||
90
lib/models/home_model.dart
Normal file
90
lib/models/home_model.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
class WeightModel {
|
||||
final String documentId;
|
||||
final String name;
|
||||
final double weight;
|
||||
final DateTime date;
|
||||
final double weightChange;
|
||||
|
||||
WeightModel({
|
||||
required this.weight,
|
||||
required this.date,
|
||||
required this.weightChange,
|
||||
required this.name,
|
||||
required this.documentId,
|
||||
});
|
||||
|
||||
static WeightModel fromJson(Map<String, dynamic> json) {
|
||||
return WeightModel(
|
||||
weight: json['weight'],
|
||||
date: DateTime.parse(json['date']),
|
||||
weightChange: json['weightChange'],
|
||||
name: json['name'],
|
||||
documentId: json['\$id'],
|
||||
);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toMapForAppwrite(WeightModel weightModel) {
|
||||
return {
|
||||
'weight': weightModel.weight,
|
||||
'date': weightModel.date.toIso8601String(),
|
||||
'weightChange': weightModel.weightChange,
|
||||
'name': weightModel.name,
|
||||
//'\$id': weightModel.documentId,
|
||||
};
|
||||
}
|
||||
|
||||
// An empty instance for initialization or default values
|
||||
static final empty = WeightModel(
|
||||
weight: 0.0,
|
||||
date: DateTime.now(),
|
||||
weightChange: 0.0,
|
||||
name: 'Joe',
|
||||
documentId: '00',
|
||||
);
|
||||
|
||||
// Sample data for testing and demonstration purposes
|
||||
// static List<WeightModel> sampleData = [
|
||||
// WeightModel(
|
||||
// weight: 70.0,
|
||||
// date: DateTime(2024, 1, 1),
|
||||
// weightChange: 0.0,
|
||||
// name: 'Joe',
|
||||
// documentId: '699e0c79003da44797d9',
|
||||
// ),
|
||||
// WeightModel(
|
||||
// weight: 69.2,
|
||||
// date: DateTime(2024, 1, 15),
|
||||
// weightChange: -0.5,
|
||||
// name: 'Joe',
|
||||
// documentId: '699e0ca5002697256161',
|
||||
// ),
|
||||
// WeightModel(
|
||||
// weight: 68.0,
|
||||
// date: DateTime(2024, 2, 1),
|
||||
// weightChange: -1.5,
|
||||
// name: 'Joe',
|
||||
// documentId: '699e0cdc00352f911abe',
|
||||
// ),
|
||||
// WeightModel(
|
||||
// weight: 100.0,
|
||||
// date: DateTime(2024, 1, 1),
|
||||
// weightChange: 0.0,
|
||||
// name: 'Karl',
|
||||
// documentId: '699e0cfd0014079d20b7',
|
||||
// ),
|
||||
// WeightModel(
|
||||
// weight: 95.5,
|
||||
// date: DateTime(2024, 1, 15),
|
||||
// weightChange: -4.5,
|
||||
// name: 'Karl',
|
||||
// documentId: '699e0d2100090bef253b',
|
||||
// ),
|
||||
// WeightModel(
|
||||
// weight: 90.0,
|
||||
// date: DateTime(2024, 2, 1),
|
||||
// weightChange: -5.5,
|
||||
// name: 'Karl',
|
||||
// documentId: '699e0d40001f669c6a15',
|
||||
// ),
|
||||
// ];
|
||||
}
|
||||
128
lib/pages/home/home_view.dart
Normal file
128
lib/pages/home/home_view.dart
Normal file
@@ -0,0 +1,128 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../controllers/home_controller.dart';
|
||||
import '../../models/home_model.dart';
|
||||
import '../../widgets/glass_app_bar.dart';
|
||||
import '../../widgets/person_weight_card.dart';
|
||||
|
||||
class HomePage extends GetView<HomeController> {
|
||||
static const String namedRoute = '/home-page';
|
||||
const HomePage({super.key});
|
||||
|
||||
/// Gruppiert eine flache Liste nach `name` und gibt eine Map zurück,
|
||||
/// die je Person alle zugehörigen Einträge enthält.
|
||||
Map<String, List<WeightModel>> _groupByName(List<WeightModel> weights) {
|
||||
final map = <String, List<WeightModel>>{};
|
||||
for (final w in weights) {
|
||||
map.putIfAbsent(w.name, () => []).add(w);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final homeCtrl = controller;
|
||||
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: GlassAppBar(
|
||||
title: 'Weight Tracker',
|
||||
subtitle: 'Verfolge dein Gewicht',
|
||||
),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Color(0xFF0D0F14),
|
||||
Color(0xFF141824),
|
||||
Color(0xFF1A2035),
|
||||
Color(0xFF0F1520),
|
||||
],
|
||||
stops: [0.0, 0.35, 0.65, 1.0],
|
||||
),
|
||||
),
|
||||
child: Obx(() {
|
||||
if (homeCtrl.isloading.value) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (homeCtrl.weights.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'Noch keine Gewichtsangaben.\nKlicke auf das "+" Symbol, um deinen ersten Eintrag hinzuzufügen.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 18, color: Colors.white70),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final grouped = _groupByName(homeCtrl.weights);
|
||||
final names = grouped.keys.toList()..sort();
|
||||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Responsive: ab 700 px Breite → 2-spaltiges Grid
|
||||
final isWide = constraints.maxWidth >= 700;
|
||||
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).padding.top + 96,
|
||||
left: isWide ? 24 : 16,
|
||||
right: isWide ? 24 : 16,
|
||||
bottom: 24,
|
||||
),
|
||||
sliver: isWide
|
||||
? SliverGrid(
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 600,
|
||||
mainAxisSpacing: 16,
|
||||
crossAxisSpacing: 16,
|
||||
childAspectRatio: 0.95,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, i) => PersonWeightCard(
|
||||
personName: names[i],
|
||||
entries: grouped[names[i]]!,
|
||||
onAddWeight: () => homeCtrl.openAddDialog(
|
||||
names[i],
|
||||
grouped[names[i]]!.first.documentId,
|
||||
),
|
||||
onEditEntry: (entry) =>
|
||||
homeCtrl.openEditDialog(entry),
|
||||
),
|
||||
childCount: names.length,
|
||||
),
|
||||
)
|
||||
: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, i) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: PersonWeightCard(
|
||||
personName: names[i],
|
||||
entries: grouped[names[i]]!,
|
||||
onAddWeight: () => homeCtrl.openAddDialog(
|
||||
names[i],
|
||||
grouped[names[i]]!.first.documentId,
|
||||
),
|
||||
onEditEntry: (entry) =>
|
||||
homeCtrl.openEditDialog(entry),
|
||||
),
|
||||
),
|
||||
childCount: names.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
137
lib/services/appwrite_service.dart
Normal file
137
lib/services/appwrite_service.dart
Normal file
@@ -0,0 +1,137 @@
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
|
||||
import '../configs/environment.dart';
|
||||
|
||||
class AppwriteService {
|
||||
static final String endpoint = Environment.appwritePublicEndpoint;
|
||||
static final String projectId = Environment.appwriteProjectId;
|
||||
static final String realtimeCollectionId =
|
||||
Environment.appwriteRealtimeCollectionId;
|
||||
static final String databaseId = Environment.appwriteDatabaseId;
|
||||
static final String userEmail = Environment.appwriteUserEMail;
|
||||
static final String passwd = Environment.appwritePasswd;
|
||||
|
||||
final Client _client = Client().setProject(projectId).setEndpoint(endpoint);
|
||||
|
||||
late final Databases _databases;
|
||||
late final Account _account;
|
||||
bool _sessionActive = false;
|
||||
|
||||
AppwriteService._internal() {
|
||||
_databases = Databases(_client);
|
||||
_account = Account(_client);
|
||||
}
|
||||
|
||||
static final AppwriteService _instance = AppwriteService._internal();
|
||||
|
||||
/// Singleton instance getter
|
||||
factory AppwriteService() => _instance;
|
||||
|
||||
/// Login mit Email/Passwort. Erstellt nur eine neue Session wenn noch keine aktiv ist.
|
||||
Future<bool> login() async {
|
||||
if (_sessionActive) return true;
|
||||
try {
|
||||
await _account.getSession(sessionId: 'current');
|
||||
_sessionActive = true;
|
||||
return true;
|
||||
} catch (_) {
|
||||
// Keine aktive Session – neu einloggen
|
||||
}
|
||||
try {
|
||||
await _account.createEmailPasswordSession(
|
||||
email: userEmail,
|
||||
password: passwd,
|
||||
);
|
||||
_sessionActive = true;
|
||||
print('Appwrite Login erfolgreich');
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('Fehler beim Login: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Get List<Document> from Realtime Collection
|
||||
Future<List<Document>> getDocumentsFromCollection() async {
|
||||
try {
|
||||
final documents = await _databases.listDocuments(
|
||||
databaseId: databaseId,
|
||||
collectionId: realtimeCollectionId,
|
||||
queries: [Query.orderAsc('name'), Query.orderDesc('date')],
|
||||
);
|
||||
return documents.documents;
|
||||
} catch (e) {
|
||||
print('Fehler beim Abrufen der Dokumente: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Get Document per Id from Realtime Collection
|
||||
Future<Document?> getDocumentById(String documentId) async {
|
||||
try {
|
||||
final document = await _databases.getDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: realtimeCollectionId,
|
||||
documentId: documentId,
|
||||
);
|
||||
return document;
|
||||
} catch (e) {
|
||||
print('Fehler beim Abrufen des Dokuments: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Save a new document to Realtime Collection
|
||||
Future<bool> createDocumentInCollection(Map<String, dynamic> data) async {
|
||||
try {
|
||||
await _databases.createDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: realtimeCollectionId,
|
||||
documentId: ID.unique(),
|
||||
data: data,
|
||||
);
|
||||
print('Dokument erfolgreich erstellt');
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('Fehler beim Erstellen des Dokuments: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update an existing document in Realtime Collection
|
||||
Future<bool> updateDocumentInCollection(
|
||||
String documentId,
|
||||
Map<String, dynamic> data,
|
||||
) async {
|
||||
try {
|
||||
await _databases.updateDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: realtimeCollectionId,
|
||||
documentId: documentId,
|
||||
data: data,
|
||||
);
|
||||
print('Dokument erfolgreich aktualisiert');
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('Fehler beim Aktualisieren des Dokuments: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a document from Realtime Collection
|
||||
Future<bool> deleteDocumentFromCollection(String documentId) async {
|
||||
try {
|
||||
await _databases.deleteDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: realtimeCollectionId,
|
||||
documentId: documentId,
|
||||
);
|
||||
print('Dokument erfolgreich gelöscht');
|
||||
return true;
|
||||
} catch (e) {
|
||||
print('Fehler beim Löschen des Dokuments: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
565
lib/widgets/add_weight_dialog.dart
Normal file
565
lib/widgets/add_weight_dialog.dart
Normal file
@@ -0,0 +1,565 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../models/home_model.dart';
|
||||
|
||||
class AddWeightDialog extends StatefulWidget {
|
||||
final String userId;
|
||||
final String personName;
|
||||
|
||||
/// Letztes bekanntes Gewicht dieser Person – wird für weightChange benötigt.
|
||||
final double lastWeight;
|
||||
|
||||
/// Wenn gesetzt → Edit-Modus: Felder werden vorausgefüllt.
|
||||
final WeightModel? existingEntry;
|
||||
|
||||
const AddWeightDialog({
|
||||
super.key,
|
||||
required this.userId,
|
||||
required this.personName,
|
||||
required this.lastWeight,
|
||||
this.existingEntry,
|
||||
});
|
||||
|
||||
/// Öffnet den Dialog zum Hinzufügen eines neuen Eintrags.
|
||||
static Future<WeightModel?> show({
|
||||
required String userId,
|
||||
required String personName,
|
||||
required double lastWeight,
|
||||
}) {
|
||||
return Get.dialog<WeightModel>(
|
||||
AddWeightDialog(
|
||||
userId: userId,
|
||||
personName: personName,
|
||||
lastWeight: lastWeight,
|
||||
),
|
||||
barrierColor: Colors.black.withValues(alpha: 0.55),
|
||||
);
|
||||
}
|
||||
|
||||
/// Öffnet den Dialog zum Bearbeiten eines vorhandenen Eintrags.
|
||||
/// [previousWeight] = Gewicht des Eintrags VOR dem zu bearbeitenden.
|
||||
static Future<WeightModel?> showEdit({
|
||||
required WeightModel entry,
|
||||
required double previousWeight,
|
||||
}) {
|
||||
return Get.dialog<WeightModel>(
|
||||
AddWeightDialog(
|
||||
userId: entry.documentId,
|
||||
personName: entry.name,
|
||||
lastWeight: previousWeight,
|
||||
existingEntry: entry,
|
||||
),
|
||||
barrierColor: Colors.black.withValues(alpha: 0.55),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
State<AddWeightDialog> createState() => _AddWeightDialogState();
|
||||
}
|
||||
|
||||
class _AddWeightDialogState extends State<AddWeightDialog>
|
||||
with SingleTickerProviderStateMixin {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _weightController = TextEditingController();
|
||||
late final TextEditingController _nameController;
|
||||
|
||||
DateTime _selectedDate = DateTime.now();
|
||||
double? _parsedWeight;
|
||||
late AnimationController _anim;
|
||||
late Animation<double> _fadeScale;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nameController = TextEditingController(text: widget.personName);
|
||||
// Edit-Modus: Felder vorausfüllen
|
||||
if (widget.existingEntry != null) {
|
||||
final e = widget.existingEntry!;
|
||||
_weightController.text = e.weight.toString().replaceAll('.', ',');
|
||||
_parsedWeight = e.weight;
|
||||
_selectedDate = e.date;
|
||||
}
|
||||
_anim = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 220),
|
||||
);
|
||||
_fadeScale = CurvedAnimation(parent: _anim, curve: Curves.easeOutBack);
|
||||
_anim.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_weightController.dispose();
|
||||
_nameController.dispose();
|
||||
_anim.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
double get _weightChange {
|
||||
if (_parsedWeight == null || widget.lastWeight == 0) return 0;
|
||||
return double.parse(
|
||||
(_parsedWeight! - widget.lastWeight).toStringAsFixed(2),
|
||||
);
|
||||
}
|
||||
|
||||
Color get _changeColor {
|
||||
if (_weightChange < 0) return const Color(0xFF4FFFB0);
|
||||
if (_weightChange > 0) return const Color(0xFFFF6B6B);
|
||||
return Colors.white54;
|
||||
}
|
||||
|
||||
String get _changeLabel {
|
||||
if (_parsedWeight == null) return '';
|
||||
if (widget.lastWeight == 0) return 'Erster Eintrag';
|
||||
final sign = _weightChange > 0 ? '+' : '';
|
||||
return '$sign${_weightChange.toStringAsFixed(1)} kg';
|
||||
}
|
||||
|
||||
Future<void> _pickDate() async {
|
||||
final picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedDate,
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2100),
|
||||
builder: (context, child) => Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
colorScheme: const ColorScheme.dark(
|
||||
primary: Color(0xFF7B9FFF),
|
||||
onSurface: Colors.white,
|
||||
surface: Color(0xFF1A2035),
|
||||
),
|
||||
),
|
||||
child: child!,
|
||||
),
|
||||
);
|
||||
if (picked != null) setState(() => _selectedDate = picked);
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
final name = _nameController.text.trim();
|
||||
final entry = WeightModel(
|
||||
// Im Edit-Modus dieselbe ID behalten
|
||||
documentId:
|
||||
widget.existingEntry?.documentId ??
|
||||
DateTime.now().millisecondsSinceEpoch.toString(),
|
||||
|
||||
name: name,
|
||||
weight: _parsedWeight!,
|
||||
date: _selectedDate,
|
||||
weightChange: widget.lastWeight == 0 ? 0 : _weightChange,
|
||||
);
|
||||
Navigator.of(context).pop(entry);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScaleTransition(
|
||||
scale: _fadeScale,
|
||||
child: FadeTransition(
|
||||
opacity: _anim,
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 460),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 40),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 24, sigmaY: 24),
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// ── Titelzeile ──────────────────────────
|
||||
_DialogHeader(
|
||||
personName: widget.personName,
|
||||
isEdit: widget.existingEntry != null,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 20, 20, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// Name
|
||||
_GlassField(
|
||||
label: 'Name',
|
||||
icon: Icons.person_outline_rounded,
|
||||
child: TextFormField(
|
||||
controller: _nameController,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
),
|
||||
decoration: _inputDecoration('z. B. Joe'),
|
||||
validator: (v) =>
|
||||
(v == null || v.trim().isEmpty)
|
||||
? 'Name eingeben'
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Gewicht
|
||||
_GlassField(
|
||||
label: 'Gewicht',
|
||||
icon: Icons.monitor_weight_outlined,
|
||||
child: TextFormField(
|
||||
controller: _weightController,
|
||||
keyboardType:
|
||||
const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(
|
||||
RegExp(r'^\d*[.,]?\d*'),
|
||||
),
|
||||
],
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
),
|
||||
decoration: _inputDecoration(
|
||||
'z. B. 72,5',
|
||||
),
|
||||
onChanged: (v) {
|
||||
final parsed = double.tryParse(
|
||||
v.replaceAll(',', '.'),
|
||||
);
|
||||
setState(() => _parsedWeight = parsed);
|
||||
},
|
||||
validator: (v) {
|
||||
if (v == null || v.isEmpty) {
|
||||
return 'Gewicht eingeben';
|
||||
}
|
||||
if (double.tryParse(
|
||||
v.replaceAll(',', '.'),
|
||||
) ==
|
||||
null) {
|
||||
return 'Ungültige Zahl';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Datum
|
||||
_GlassField(
|
||||
label: 'Datum',
|
||||
icon: Icons.calendar_today_outlined,
|
||||
child: InkWell(
|
||||
onTap: _pickDate,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: InputDecorator(
|
||||
decoration: _inputDecoration(''),
|
||||
child: Text(
|
||||
DateFormat(
|
||||
'dd.MM.yyyy',
|
||||
).format(_selectedDate),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Vorschau weightChange
|
||||
if (_parsedWeight != null)
|
||||
_ChangePreview(
|
||||
label: _changeLabel,
|
||||
color: _changeColor,
|
||||
lastWeight: widget.lastWeight,
|
||||
),
|
||||
if (_parsedWeight != null)
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Buttons
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _GlassButton(
|
||||
label: 'Abbrechen',
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(),
|
||||
primary: false,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _GlassButton(
|
||||
label: widget.existingEntry != null
|
||||
? 'Speichern'
|
||||
: 'Hinzufügen',
|
||||
onPressed: _submit,
|
||||
primary: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
), // Form
|
||||
), // Container
|
||||
), // Material
|
||||
), // BackdropFilter
|
||||
), // ClipRRect
|
||||
), // Padding
|
||||
), // ConstrainedBox
|
||||
), // Center
|
||||
), // FadeTransition
|
||||
); // ScaleTransition
|
||||
}
|
||||
|
||||
InputDecoration _inputDecoration(String hint) => InputDecoration(
|
||||
hintText: hint,
|
||||
hintStyle: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.35),
|
||||
fontSize: 14,
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white.withValues(alpha: 0.07),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Colors.white.withValues(alpha: 0.2)),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Colors.white.withValues(alpha: 0.2)),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: Color(0xFF7B9FFF), width: 1.5),
|
||||
),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: Color(0xFFFF6B6B), width: 1.2),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: Color(0xFFFF6B6B), width: 1.5),
|
||||
),
|
||||
errorStyle: const TextStyle(color: Color(0xFFFF6B6B), fontSize: 11),
|
||||
);
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Hilfs-Widgets
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
class _DialogHeader extends StatelessWidget {
|
||||
final String personName;
|
||||
final bool isEdit;
|
||||
const _DialogHeader({required this.personName, this.isEdit = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 18, 12, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.06),
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Colors.white.withValues(alpha: 0.12)),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isEdit ? Icons.edit_outlined : Icons.add_circle_outline_rounded,
|
||||
color: const Color(0xFF7B9FFF),
|
||||
size: 22,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
isEdit ? 'Eintrag bearbeiten' : 'Gewicht hinzufügen',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
personName,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.55),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: Icon(
|
||||
Icons.close_rounded,
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
size: 20,
|
||||
),
|
||||
splashRadius: 18,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _GlassField extends StatelessWidget {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final Widget child;
|
||||
|
||||
const _GlassField({
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, color: Colors.white.withValues(alpha: 0.5), size: 14),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.6),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.8,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
child,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ChangePreview extends StatelessWidget {
|
||||
final String label;
|
||||
final Color color;
|
||||
final double lastWeight;
|
||||
|
||||
const _ChangePreview({
|
||||
required this.label,
|
||||
required this.color,
|
||||
required this.lastWeight,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: color.withValues(alpha: 0.35)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.swap_vert_rounded, color: color, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
lastWeight == 0 ? label : 'Änderung zum letzten Eintrag: ',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.7),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
if (lastWeight != 0)
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _GlassButton extends StatelessWidget {
|
||||
final String label;
|
||||
final VoidCallback onPressed;
|
||||
final bool primary;
|
||||
|
||||
const _GlassButton({
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
required this.primary,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 13),
|
||||
decoration: BoxDecoration(
|
||||
color: primary
|
||||
? const Color(0xFF7B9FFF).withValues(alpha: 0.25)
|
||||
: Colors.white.withValues(alpha: 0.07),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: primary
|
||||
? const Color(0xFF7B9FFF).withValues(alpha: 0.6)
|
||||
: Colors.white.withValues(alpha: 0.15),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: primary ? const Color(0xFF7B9FFF) : Colors.white60,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14,
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
144
lib/widgets/glass_app_bar.dart
Normal file
144
lib/widgets/glass_app_bar.dart
Normal file
@@ -0,0 +1,144 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'outlined_text.dart';
|
||||
|
||||
class GlassAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
final List<Widget>? actions;
|
||||
final Widget? leading;
|
||||
final double height;
|
||||
final Color glassColor;
|
||||
final double blurSigma;
|
||||
final double borderOpacity;
|
||||
|
||||
const GlassAppBar({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
this.actions,
|
||||
this.leading,
|
||||
this.height = 80,
|
||||
this.glassColor = const Color(0x22FFFFFF),
|
||||
this.blurSigma = 18,
|
||||
this.borderOpacity = 0.25,
|
||||
});
|
||||
|
||||
@override
|
||||
Size get preferredSize => Size.fromHeight(height);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return ClipRect(
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: blurSigma, sigmaY: blurSigma),
|
||||
child: Container(
|
||||
height: height,
|
||||
decoration: BoxDecoration(
|
||||
color: glassColor,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Colors.white.withValues(alpha: borderOpacity),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (leading != null) ...[leading!, const SizedBox(width: 12)],
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
OutlinedText(
|
||||
title,
|
||||
style: theme.textTheme.headlineSmall!.copyWith(
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.8,
|
||||
fontSize: 26,
|
||||
),
|
||||
fillColor: Colors.white,
|
||||
strokeColor: Colors.black,
|
||||
strokeWidth: 2.5,
|
||||
),
|
||||
if (subtitle != null) ...[
|
||||
const SizedBox(height: 3),
|
||||
OutlinedText(
|
||||
subtitle!,
|
||||
style: theme.textTheme.bodyMedium!.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 0.4,
|
||||
),
|
||||
fillColor: Colors.white.withValues(alpha: 0.95),
|
||||
strokeColor: Colors.black,
|
||||
strokeWidth: 1.5,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
if (actions != null)
|
||||
Row(mainAxisSize: MainAxisSize.min, children: actions!),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ein Icon-Button im Glas-Stil, passend zur GlassAppBar.
|
||||
class GlassIconButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final VoidCallback? onPressed;
|
||||
final String? tooltip;
|
||||
final Color? color;
|
||||
|
||||
const GlassIconButton({
|
||||
super.key,
|
||||
required this.icon,
|
||||
this.onPressed,
|
||||
this.tooltip,
|
||||
this.color,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final iconColor =
|
||||
color ??
|
||||
Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.85);
|
||||
return Tooltip(
|
||||
message: tooltip ?? '',
|
||||
child: InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 8, sigmaY: 8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.12),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.25)),
|
||||
),
|
||||
child: Icon(icon, color: iconColor, size: 22),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
38
lib/widgets/outlined_text.dart
Normal file
38
lib/widgets/outlined_text.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Rendert Text mit einer farbigen Kontur (Stroke) via Stack.
|
||||
class OutlinedText extends StatelessWidget {
|
||||
final String text;
|
||||
final TextStyle style;
|
||||
final Color fillColor;
|
||||
final Color strokeColor;
|
||||
final double strokeWidth;
|
||||
|
||||
const OutlinedText(
|
||||
this.text, {
|
||||
super.key,
|
||||
required this.style,
|
||||
required this.fillColor,
|
||||
this.strokeColor = Colors.black,
|
||||
this.strokeWidth = 2.0,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final strokeStyle = style.copyWith(
|
||||
foreground: Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = strokeWidth
|
||||
..strokeJoin = StrokeJoin.round
|
||||
..color = strokeColor,
|
||||
);
|
||||
final fillStyle = style.copyWith(color: fillColor);
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Text(text, style: strokeStyle),
|
||||
Text(text, style: fillStyle),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
434
lib/widgets/person_weight_card.dart
Normal file
434
lib/widgets/person_weight_card.dart
Normal file
@@ -0,0 +1,434 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../models/home_model.dart';
|
||||
import 'outlined_text.dart';
|
||||
|
||||
class PersonWeightCard extends StatelessWidget {
|
||||
/// Alle Einträge einer Person, absteigend nach Datum sortiert.
|
||||
final String personName;
|
||||
final List<WeightModel> entries;
|
||||
final VoidCallback? onAddWeight;
|
||||
|
||||
/// Wird aufgerufen wenn ein Verlaufseintrag oder der Header-Eintrag
|
||||
/// zum Bearbeiten angeklickt wird.
|
||||
final void Function(WeightModel entry)? onEditEntry;
|
||||
|
||||
const PersonWeightCard({
|
||||
super.key,
|
||||
required this.personName,
|
||||
required this.entries,
|
||||
this.onAddWeight,
|
||||
this.onEditEntry,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Defensiv: sicher sortiert (neuestes zuerst)
|
||||
final sorted = [...entries]..sort((a, b) => b.date.compareTo(a.date));
|
||||
|
||||
final current = sorted.first;
|
||||
final history = sorted.skip(1).toList();
|
||||
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 16, sigmaY: 16),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.07),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.15),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// ── Header ──────────────────────────────────────────
|
||||
_CardHeader(
|
||||
current: current,
|
||||
name: personName,
|
||||
onAddWeight: onAddWeight,
|
||||
onEdit: onEditEntry != null
|
||||
? () => onEditEntry!(current)
|
||||
: null,
|
||||
),
|
||||
|
||||
// ── Historische Einträge ─────────────────────────────
|
||||
if (history.isNotEmpty) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 6,
|
||||
),
|
||||
child: Text(
|
||||
'Verlauf',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.45),
|
||||
fontSize: 12,
|
||||
letterSpacing: 1.2,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 220),
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12,
|
||||
right: 12,
|
||||
bottom: 12,
|
||||
),
|
||||
itemCount: history.length,
|
||||
separatorBuilder: (_, _) => Divider(
|
||||
color: Colors.white.withValues(alpha: 0.08),
|
||||
height: 1,
|
||||
),
|
||||
itemBuilder: (context, i) => _HistoryRow(
|
||||
entry: history[i],
|
||||
onTap: onEditEntry != null
|
||||
? () => onEditEntry!(history[i])
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: Text(
|
||||
'Noch keine älteren Einträge.',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.35),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Header
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
class _CardHeader extends StatelessWidget {
|
||||
final WeightModel current;
|
||||
final String name;
|
||||
final VoidCallback? onAddWeight;
|
||||
final VoidCallback? onEdit;
|
||||
|
||||
const _CardHeader({
|
||||
required this.current,
|
||||
required this.name,
|
||||
this.onAddWeight,
|
||||
this.onEdit,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final changeColor = current.weightChange < 0
|
||||
? const Color(0xFF4FFFB0)
|
||||
: current.weightChange > 0
|
||||
? const Color(0xFFFF6B6B)
|
||||
: Colors.white54;
|
||||
|
||||
final changeIcon = current.weightChange < 0
|
||||
? Icons.trending_down_rounded
|
||||
: current.weightChange > 0
|
||||
? Icons.trending_up_rounded
|
||||
: Icons.remove_rounded;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 18, 16, 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.05),
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Colors.white.withValues(alpha: 0.1)),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Avatar
|
||||
CircleAvatar(
|
||||
radius: 26,
|
||||
backgroundColor: Colors.white.withValues(alpha: 0.12),
|
||||
child: OutlinedText(
|
||||
name[0].toUpperCase(),
|
||||
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.w900),
|
||||
fillColor: Colors.white,
|
||||
strokeColor: Colors.black,
|
||||
strokeWidth: 1.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
// Name + Datum
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
OutlinedText(
|
||||
name,
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.4,
|
||||
),
|
||||
fillColor: Colors.white,
|
||||
strokeColor: Colors.black,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'Zuletzt: ${DateFormat('dd.MM.yyyy').format(current.date)}',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.5),
|
||||
fontSize: 12,
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Add-Button
|
||||
if (onAddWeight != null) _GlassAddButton(onPressed: onAddWeight!),
|
||||
if (onEdit != null) ...[
|
||||
const SizedBox(width: 6),
|
||||
_GlassEditButton(onPressed: onEdit!),
|
||||
],
|
||||
const SizedBox(width: 8),
|
||||
// Aktuelles Gewicht + Änderung
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
OutlinedText(
|
||||
'${current.weight.toStringAsFixed(1)} kg',
|
||||
style: const TextStyle(
|
||||
fontSize: 26,
|
||||
fontWeight: FontWeight.w900,
|
||||
letterSpacing: 0.2,
|
||||
),
|
||||
fillColor: Colors.white,
|
||||
strokeColor: Colors.black,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(changeIcon, color: changeColor, size: 16),
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
current.weightChange == 0
|
||||
? '±0.0 kg'
|
||||
: '${current.weightChange > 0 ? '+' : ''}${current.weightChange.toStringAsFixed(1)} kg',
|
||||
style: TextStyle(
|
||||
color: changeColor,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Verlaufs-Zeile
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
class _HistoryRow extends StatelessWidget {
|
||||
final WeightModel entry;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const _HistoryRow({required this.entry, this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final changeColor = entry.weightChange < 0
|
||||
? const Color(0xFF4FFFB0)
|
||||
: entry.weightChange > 0
|
||||
? const Color(0xFFFF6B6B)
|
||||
: Colors.white54;
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 11, horizontal: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
// Datum
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
DateFormat('dd.MM.yyyy').format(entry.date),
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.6),
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
// Gewicht
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
'${entry.weight.toStringAsFixed(1)} kg',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
// Änderung
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Icon(
|
||||
entry.weightChange < 0
|
||||
? Icons.arrow_downward_rounded
|
||||
: entry.weightChange > 0
|
||||
? Icons.arrow_upward_rounded
|
||||
: Icons.remove_rounded,
|
||||
color: changeColor,
|
||||
size: 14,
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
entry.weightChange == 0
|
||||
? '±0.0'
|
||||
: '${entry.weightChange > 0 ? '+' : ''}${entry.weightChange.toStringAsFixed(1)}',
|
||||
style: TextStyle(
|
||||
color: changeColor,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Edit-Button – gut sichtbar auf Mobile
|
||||
if (onTap != null) ...[
|
||||
const SizedBox(width: 10),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 9, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.25),
|
||||
),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.edit_outlined,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Glas-Add-Button (runder "+"-Button passend zum Karten-Header)
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
/// Ein runder Bearbeiten-Button im Glas-Stil.
|
||||
class _GlassEditButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
|
||||
const _GlassEditButton({required this.onPressed});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
message: 'Eintrag bearbeiten',
|
||||
child: InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 8, sigmaY: 8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.10),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.25)),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.edit_outlined,
|
||||
color: Colors.white,
|
||||
size: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Glas-Add-Button
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
class _GlassAddButton extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
|
||||
const _GlassAddButton({required this.onPressed});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
message: 'Gewicht hinzufügen',
|
||||
child: InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 8, sigmaY: 8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.14),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.add_rounded,
|
||||
color: Colors.white,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user