diff --git a/lib/pages/mood_page.dart b/lib/pages/mood_page.dart index 546c6f1..8c2447d 100644 --- a/lib/pages/mood_page.dart +++ b/lib/pages/mood_page.dart @@ -1,17 +1,15 @@ import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:smoke_cess_app/providers/input_provider.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/widgets/mood_form.dart'; +import 'package:smoke_cess_app/widgets/mood_view.dart'; +import 'package:smoke_cess_app/widgets/view_form_page.dart'; class MoodPage extends StatelessWidget { const MoodPage({super.key}); @override Widget build(BuildContext context) { - return Center( - child: ChangeNotifierProvider( - create: (context) => InputProvider(), - child: const MoodForm(), - )); + return const ViewFormPage( + form: MoodForm(), view: MoodView(), page: Pages.mood); } } diff --git a/lib/pages/relapse_page.dart b/lib/pages/relapse_page.dart index 75e007d..b0edf96 100644 --- a/lib/pages/relapse_page.dart +++ b/lib/pages/relapse_page.dart @@ -1,17 +1,16 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/widgets/relapse_form.dart'; -import '../providers/input_provider.dart'; +import 'package:smoke_cess_app/widgets/relapse_view.dart'; +import '../widgets/view_form_page.dart'; class RelapsePage extends StatelessWidget { const RelapsePage({super.key}); @override Widget build(BuildContext context) { - return Center( - child: ChangeNotifierProvider( - create: (context) => InputProvider(), - child: const RelapseForm(), - )); + return const ViewFormPage( + form: RelapseForm(), view: RelapseView(), page: Pages.relapse); } } diff --git a/lib/pages/sleep_page.dart b/lib/pages/sleep_page.dart index 22221f3..3cf3fd5 100644 --- a/lib/pages/sleep_page.dart +++ b/lib/pages/sleep_page.dart @@ -1,17 +1,15 @@ import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:smoke_cess_app/providers/input_provider.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; import 'package:smoke_cess_app/widgets/sleep_form.dart'; +import 'package:smoke_cess_app/widgets/sleep_view.dart'; +import 'package:smoke_cess_app/widgets/view_form_page.dart'; class SleepPage extends StatelessWidget { const SleepPage({super.key}); @override Widget build(BuildContext context) { - return Center( - child: ChangeNotifierProvider( - create: (context) => InputProvider(), - child: const SleepForm(), - )); + return const ViewFormPage( + form: SleepForm(), view: SleepView(), page: Pages.sleep); } } diff --git a/lib/widgets/view_form_page.dart b/lib/widgets/view_form_page.dart new file mode 100644 index 0000000..843f66e --- /dev/null +++ b/lib/widgets/view_form_page.dart @@ -0,0 +1,51 @@ +import 'package:awesome_dialog/awesome_dialog.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:smoke_cess_app/services/pages_service.dart'; + +import '../providers/input_provider.dart'; +import '../providers/page_provider.dart'; +import '../providers/tasks_provider.dart'; + +class ViewFormPage extends StatelessWidget { + final Widget form; + final Widget view; + final Pages page; + const ViewFormPage( + {super.key, required this.form, required this.view, required this.page}); + + void showPopUp(BuildContext context) { + AwesomeDialog( + context: context, + dialogType: DialogType.info, + title: 'Schon gemacht!', + desc: 'Der Eintrag wurde erfolgreich gespeichert', + ).show(); + } + + @override + Widget build(BuildContext context) { + PageProvider pageProvider = context.watch(); + TasksProvider tasksProvider = context.watch(); + return Wrap(children: [ + Align( + alignment: Alignment.topLeft, + child: IconButton( + icon: pageProvider.showForm + ? const Icon(Icons.arrow_back, color: Colors.black) + : const Icon(Icons.add_outlined, color: Colors.black), + onPressed: tasksProvider.tasks[page] ?? true + ? pageProvider.swap + : () => showPopUp(context), + ), + ), + pageProvider.showForm + ? Center( + child: ChangeNotifierProvider( + create: (context) => InputProvider(), + child: form, + )) + : Center(child: view) + ]); + } +}