From 8143a910200a339df96abc31824289f5685df50a Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Sat, 4 Mar 2023 17:58:04 +0100 Subject: [PATCH] back button to appbar, added round add button to add entries --- lib/pages/main_page.dart | 33 ++++++++++++++++++++-------- lib/widgets/round_button_widget.dart | 21 ++++++++++++++++++ lib/widgets/view_form_page.dart | 22 ++++++++----------- 3 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 lib/widgets/round_button_widget.dart diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 10ff0ec..026d707 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -38,22 +38,37 @@ class MyHomePageState extends State { @override Widget build(BuildContext context) { - var settingsModel = context.watch(); - var tasksModel = context.watch(); - _isConfigured = settingsModel.initialized; + var settingsProvider = context.watch(); + var tasksProvider = context.watch(); + PageProvider pageProvider = context.watch(); + + _isConfigured = settingsProvider.initialized; return Scaffold( appBar: AppBar( - title: Text( - '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')), - body: SingleChildScrollView( - child: pages.values.elementAt(_selectedIndex)['page'], - ), + title: Row( + children: [ + Stack( + children: [ + const SizedBox( + width: 70, + ), + if (pageProvider.showForm) + IconButton( + icon: const Icon(Icons.arrow_back, color: Colors.white), + onPressed: pageProvider.swap), + ], + ), + Text( + '${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsProvider.settings?.group}" : ""}') + ], + )), + body: pages.values.elementAt(_selectedIndex)['page'], bottomNavigationBar: NavigationBar( onDestinationSelected: _onItemTapped, selectedIndex: _selectedIndex, destinations: pages.keys.map((key) { return NavigationDestination( - icon: tasksModel.tasks[key] ?? false + icon: tasksProvider.tasks[key] ?? false ? MyToDoIcon(pages[key]?['icon']) : pages[key]!['icon'], label: pages[key]?['title']); diff --git a/lib/widgets/round_button_widget.dart b/lib/widgets/round_button_widget.dart new file mode 100644 index 0000000..21482bf --- /dev/null +++ b/lib/widgets/round_button_widget.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; + +class RoundAddButton extends StatelessWidget { + final VoidCallback onPressed; + + const RoundAddButton({super.key, required this.onPressed}); + + @override + Widget build(BuildContext context) { + return ElevatedButton( + onPressed: onPressed, + style: ElevatedButton.styleFrom( + shape: const CircleBorder(), + padding: const EdgeInsets.all(20), + backgroundColor: Colors.green, // <-- Button color + foregroundColor: Colors.blue, // <-- Splash color + ), + child: const Icon(Icons.add_outlined, color: Colors.white), + ); + } +} diff --git a/lib/widgets/view_form_page.dart b/lib/widgets/view_form_page.dart index 57b9271..2fa8af3 100644 --- a/lib/widgets/view_form_page.dart +++ b/lib/widgets/view_form_page.dart @@ -1,6 +1,7 @@ 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/round_button_widget.dart'; import '../providers/input_provider.dart'; import '../providers/page_provider.dart'; import '../providers/tasks_provider.dart'; @@ -17,25 +18,20 @@ class ViewFormPage extends StatelessWidget { 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 - : () => showTaskDonePopup(context, page), - ), - ), + return Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ pageProvider.showForm ? Center( child: ChangeNotifierProvider( create: (context) => InputProvider(), child: form, )) - : Center(child: view) + : Center(child: view), + if (!pageProvider.showForm) + RoundAddButton( + onPressed: tasksProvider.tasks[page] == true + ? () => pageProvider.swap() + : () => showTaskDonePopup(context, page), + ) ]); } }