cpd_2022_zi/lib/widgets/view_form_page.dart

57 lines
1.8 KiB
Dart
Raw Normal View History

2023-03-03 12:49:42 +01:00
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';
2023-03-03 16:38:08 +01:00
import '../providers/timer_provider.dart';
import '../services/date_service.dart';
import 'timer_widget.dart';
2023-03-03 12:49:42 +01:00
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});
2023-03-03 16:38:08 +01:00
void showPopup(BuildContext context) async {
TimerProvider timerProvider = context.read<TimerProvider>();
Duration duration = await getTimeTill(page);
timerProvider.startTimer(duration);
2023-03-03 12:49:42 +01:00
AwesomeDialog(
context: context,
dialogType: DialogType.info,
2023-03-03 16:38:08 +01:00
title: 'Bald erst wieder',
body: TimerWidget(duration: duration),
2023-03-03 12:49:42 +01:00
).show();
}
@override
Widget build(BuildContext context) {
PageProvider pageProvider = context.watch<PageProvider>();
TasksProvider tasksProvider = context.watch<TasksProvider>();
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
2023-03-03 16:38:08 +01:00
: () => showPopup(context),
2023-03-03 12:49:42 +01:00
),
),
pageProvider.showForm
? Center(
child: ChangeNotifierProvider(
create: (context) => InputProvider(),
child: form,
))
: Center(child: view)
]);
}
}