back button to appbar, added round add button to add entries

main
Julian Gegner 2023-03-04 17:58:04 +01:00
parent 3038efcd27
commit 8143a91020
3 changed files with 54 additions and 22 deletions

View File

@ -38,22 +38,37 @@ class MyHomePageState extends State<MyHomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var settingsModel = context.watch<SettingsProvider>(); var settingsProvider = context.watch<SettingsProvider>();
var tasksModel = context.watch<TasksProvider>(); var tasksProvider = context.watch<TasksProvider>();
_isConfigured = settingsModel.initialized; PageProvider pageProvider = context.watch<PageProvider>();
_isConfigured = settingsProvider.initialized;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Row(
'${pages.values.elementAt(_selectedIndex)['title']} ${_isConfigured ? "Gruppe ${settingsModel.settings?.group}" : ""}')), children: [
body: SingleChildScrollView( Stack(
child: pages.values.elementAt(_selectedIndex)['page'], 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( bottomNavigationBar: NavigationBar(
onDestinationSelected: _onItemTapped, onDestinationSelected: _onItemTapped,
selectedIndex: _selectedIndex, selectedIndex: _selectedIndex,
destinations: pages.keys.map((key) { destinations: pages.keys.map((key) {
return NavigationDestination( return NavigationDestination(
icon: tasksModel.tasks[key] ?? false icon: tasksProvider.tasks[key] ?? false
? MyToDoIcon(pages[key]?['icon']) ? MyToDoIcon(pages[key]?['icon'])
: pages[key]!['icon'], : pages[key]!['icon'],
label: pages[key]?['title']); label: pages[key]?['title']);

View File

@ -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),
);
}
}

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:smoke_cess_app/services/pages_service.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/input_provider.dart';
import '../providers/page_provider.dart'; import '../providers/page_provider.dart';
import '../providers/tasks_provider.dart'; import '../providers/tasks_provider.dart';
@ -17,25 +18,20 @@ class ViewFormPage extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
PageProvider pageProvider = context.watch<PageProvider>(); PageProvider pageProvider = context.watch<PageProvider>();
TasksProvider tasksProvider = context.watch<TasksProvider>(); TasksProvider tasksProvider = context.watch<TasksProvider>();
return Wrap(children: [ return Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, 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),
),
),
pageProvider.showForm pageProvider.showForm
? Center( ? Center(
child: ChangeNotifierProvider( child: ChangeNotifierProvider(
create: (context) => InputProvider(), create: (context) => InputProvider(),
child: form, child: form,
)) ))
: Center(child: view) : Center(child: view),
if (!pageProvider.showForm)
RoundAddButton(
onPressed: tasksProvider.tasks[page] == true
? () => pageProvider.swap()
: () => showTaskDonePopup(context, page),
)
]); ]);
} }
} }