Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
333c89d841 feat: implement consumer and Provider.of test things 2024-04-02 15:31:23 +02:00
3 changed files with 54 additions and 18 deletions

View file

@ -1,11 +1,25 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:migrainetracker/data_storage/daily_status_repository.dart';
import 'package:provider/provider.dart';
class DataEntryPage extends StatelessWidget {
const DataEntryPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var firstButton = ElevatedButton(
onPressed: () {
// model.logFeelingMigrainy(true);
Provider.of<DailyStatusModel>(context, listen: false)
.logFeelingMigrainy(true);
},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(12),
),
child: const Icon(Icons.error_outline, size: 120),
);
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
@ -19,14 +33,7 @@ class DataEntryPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(24),
),
child: const Icon(Icons.error_outline, size: 120,),
),
child: firstButton,
),
SizedBox.fromSize(size: const Size.fromWidth(32)),
Expanded(
@ -34,9 +41,12 @@ class DataEntryPage extends StatelessWidget {
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(24),
padding: EdgeInsets.all(12),
),
child: const Icon(
Icons.notifications_paused_sharp,
size: 120,
),
child: const Icon(Icons.notifications_paused_sharp, size: 120,),
),
),
],
@ -57,9 +67,12 @@ class DataEntryPage extends StatelessWidget {
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(24),
padding: EdgeInsets.all(12),
),
child: const Icon(
Icons.electric_bolt,
size: 120,
),
child: const Icon(Icons.electric_bolt, size: 120,),
),
),
SizedBox.fromSize(size: const Size.fromWidth(32)),
@ -69,9 +82,12 @@ class DataEntryPage extends StatelessWidget {
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(24),
padding: EdgeInsets.all(12),
),
child: const Icon(
Icons.medication_outlined,
size: 120,
),
child: const Icon(Icons.medication_outlined, size: 120,),
),
),
],
@ -92,6 +108,21 @@ class DataEntryPage extends StatelessWidget {
],
),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Consumer<DailyStatusModel>(
builder: (context, model, child) => Text(
"msg: ${model.message2}",
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w400,
),
)),
],
),
),
]);
}

View file

@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart';
class DailyStatusModel extends ChangeNotifier {
DailyEntry? currentDay;
var message = "Yay, it works!";
var message2 = "";
DailyStatusModel();
@ -23,6 +25,7 @@ class DailyStatusModel extends ChangeNotifier {
tookPainMeds: currentDay!.tookPainMeds
);
}
message2 = message;
notifyListeners();
}

View file

@ -13,6 +13,11 @@ class _NavigatorPageState extends State<NavigatorPage> {
@override
Widget build(BuildContext context) {
var pages = <Widget>[
const DataEntryPage(),
const Placeholder(),
];
return Scaffold(
appBar: AppBar(
title: const Text("Migraine Tracker"),
@ -35,10 +40,7 @@ class _NavigatorPageState extends State<NavigatorPage> {
});
},
),
body: <Widget>[
const DataEntryPage(),
const Placeholder(),
][currentPageIndex],
body: pages[currentPageIndex],
);
}
}