fixed linting warnings for the add pizza event page

This commit is contained in:
broodjeaap89 2021-09-03 17:44:15 +02:00
parent 6e331625cb
commit ff2dd7b3d6

View file

@ -15,7 +15,7 @@ import 'package:hive_flutter/hive_flutter.dart';
class AddPizzaEventPage extends StatefulWidget { class AddPizzaEventPage extends StatefulWidget {
final PizzaRecipe pizzaRecipe; final PizzaRecipe pizzaRecipe;
AddPizzaEventPage(this.pizzaRecipe); const AddPizzaEventPage(this.pizzaRecipe);
@override @override
AddPizzaEventPageState createState() => AddPizzaEventPageState(); AddPizzaEventPageState createState() => AddPizzaEventPageState();
@ -33,11 +33,11 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("Add Pizza Event"), title: const Text("Add Pizza Event"),
), ),
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Container( body: Container(
padding: EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
@ -46,13 +46,13 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
children: <Widget>[ children: <Widget>[
Row( Row(
children: <Widget>[ children: <Widget>[
Icon(Icons.title), const Icon(Icons.title),
Container(width: 25), Container(width: 25),
Expanded( Expanded(
child: TextField( child: TextField(
decoration: InputDecoration( decoration: InputDecoration(
hintText: "Event Name", hintText: "Event Name",
errorText: this.nameValidation ? "Name can\'t be empty" : null errorText: nameValidation ? """Name can't be empty""" : null
), ),
onChanged: (String newName) { onChanged: (String newName) {
setState(() { setState(() {
@ -65,7 +65,7 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
Icon(FontAwesome5.hashtag), const Icon(FontAwesome5.hashtag),
Expanded( Expanded(
child: Slider( child: Slider(
@ -73,50 +73,50 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
min: 1, min: 1,
max: 20, max: 20,
divisions: 19, divisions: 19,
label: this.pizzaCount.toString(), label: pizzaCount.toString(),
onChanged: (double newPizzaCount) { onChanged: (double newPizzaCount) {
setState(() {this.pizzaCount = newPizzaCount.round();}); setState(() {pizzaCount = newPizzaCount.round();});
}, },
) )
), ),
Container( SizedBox(
width: 25, width: 25,
child: Text(this.pizzaCount.toString()) child: Text(pizzaCount.toString())
) )
] ]
), ),
Row( Row(
children: <Widget>[ children: <Widget>[
Icon(FontAwesome5.weight_hanging), const Icon(FontAwesome5.weight_hanging),
Expanded( Expanded(
child: Slider( child: Slider(
value: doughBallSize.toDouble(), value: doughBallSize.toDouble(),
min: 100, min: 100,
max: 400, max: 400,
divisions: 30, divisions: 30,
label: this.doughBallSize.toString(), label: doughBallSize.toString(),
onChanged: (double newDoughBallSize) { onChanged: (double newDoughBallSize) {
setState(() {this.doughBallSize = newDoughBallSize.round();}); setState(() {doughBallSize = newDoughBallSize.round();});
}, },
) )
), ),
Container( SizedBox(
width: 25, width: 25,
child: Text(this.doughBallSize.toString()) child: Text(doughBallSize.toString())
) )
] ]
), ),
widget.pizzaRecipe.getIngredientsTable(this.pizzaCount, this.doughBallSize), widget.pizzaRecipe.getIngredientsTable(pizzaCount, doughBallSize),
] ]
) )
), ),
Divider(), const Divider(),
Expanded( Expanded(
flex: 45, flex: 45,
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
Column( Column(
children: this.widget.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.length > 0).map((recipeStep) { children: widget.pizzaRecipe.recipeSteps.where((recipeStep) => recipeStep.waitDescription.isNotEmpty).map((recipeStep) {
return <Widget>[ return <Widget>[
Text(recipeStep.waitDescription), Text(recipeStep.waitDescription),
Row( Row(
@ -128,10 +128,10 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
max: recipeStep.waitMax.toDouble(), max: recipeStep.waitMax.toDouble(),
divisions: recipeStep.waitMax - recipeStep.waitMin, divisions: recipeStep.waitMax - recipeStep.waitMin,
label: recipeStep.waitValue.toString(), label: recipeStep.waitValue.toString(),
onChanged: (newValue) => this.setState(() => recipeStep.waitValue = newValue.toInt()), onChanged: (newValue) => setState(() => recipeStep.waitValue = newValue.toInt()),
) )
), ),
Container( SizedBox(
width: 25, width: 25,
child: Text(recipeStep.waitValue.toString()) child: Text(recipeStep.waitValue.toString())
) )
@ -143,27 +143,26 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
] ]
) )
), ),
Divider(), const Divider(),
Spacer(), const Spacer(),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
height: 70, height: 70,
child: Container( child: Container(
color: Colors.blue, color: Colors.blue,
child: TextButton( child: TextButton(
child: Text("Review", style: TextStyle(color: Colors.white)),
onPressed: () async { onPressed: () async {
if (this.name.length == 0){ if (name.isEmpty){
setState(() { this.nameValidation = true; }); setState(() { nameValidation = true; });
return; return;
} }
setState(() { this.nameValidation = false; }); setState(() { nameValidation = false; });
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
DateTime? eventTime = await showDialog( DateTime? eventTime = await showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return ConfirmPizzaEventDialog(name: name, pizzaRecipe: this.widget.pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize); return ConfirmPizzaEventDialog(name: name, pizzaRecipe: widget.pizzaRecipe, pizzaCount: pizzaCount, doughBallSize: doughBallSize);
} }
); );
if (eventTime == null){ if (eventTime == null){
@ -171,29 +170,33 @@ class AddPizzaEventPageState extends State<AddPizzaEventPage> {
} }
// if the user waited to long on the confirmation dialog that the first step time is now in the past // if the user waited to long on the confirmation dialog that the first step time is now in the past
var durationUntilFirstStep = Duration(seconds: this.widget.pizzaRecipe.getCurrentDuration().inSeconds); final durationUntilFirstStep = Duration(seconds: widget.pizzaRecipe.getCurrentDuration().inSeconds);
var firstStepDateTime = eventTime.subtract(durationUntilFirstStep); final firstStepDateTime = eventTime.subtract(durationUntilFirstStep);
if (firstStepDateTime.isBefore(DateTime.now())){ if (firstStepDateTime.isBefore(DateTime.now())){
eventTime = DateTime.now() eventTime = DateTime.now()
.add(durationUntilFirstStep) .add(durationUntilFirstStep)
.add(const Duration(minutes: 1)); .add(const Duration(minutes: 1));
} }
var pizzaEventsBox = Hive.box<PizzaEvent>("PizzaEvents"); final pizzaEventsBox = Hive.box<PizzaEvent>("PizzaEvents");
PizzaEvent pizzaEvent = PizzaEvent( final PizzaEvent pizzaEvent = PizzaEvent(
this.name, name,
this.widget.pizzaRecipe, widget.pizzaRecipe,
this.pizzaCount, pizzaCount,
this.doughBallSize, doughBallSize,
eventTime eventTime
); );
await pizzaEventsBox.add(pizzaEvent); await pizzaEventsBox.add(pizzaEvent);
pizzaEvent.createPizzaEventNotifications(); pizzaEvent.createPizzaEventNotifications();
Navigator.pop(context); if(!mounted) {
Navigator.pop(context); // two times because of the pick recipe page return; //https://dart-lang.github.io/linter/lints/use_build_context_synchronously.html
}
Navigator.of(context).pop();
Navigator.of(context).pop(); // two times because of the pick recipe page
}, },
child: const Text("Review", style: TextStyle(color: Colors.white)),
) )
) )
) )
@ -218,7 +221,7 @@ class ConfirmPizzaEventDialog extends StatefulWidget {
) : super(key: key); ) : super(key: key);
@override @override
ConfirmPizzaEventState createState() => new ConfirmPizzaEventState(); ConfirmPizzaEventState createState() => ConfirmPizzaEventState();
} }
class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> { class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
@ -228,50 +231,48 @@ class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
eventTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration()).add(Duration(minutes: 1)); eventTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration()).add(const Duration(minutes: 1));
minTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration()); minTime = DateTime.now().add(widget.pizzaRecipe.getCurrentDuration());
} }
@override @override
Widget build(BuildContext context){ Widget build(BuildContext context){
return Dialog( return Dialog(
insetPadding: EdgeInsets.all(10), insetPadding: const EdgeInsets.all(10),
child: Container( child: Container(
padding: EdgeInsets.all(10), padding: const EdgeInsets.all(10),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
flex: 10, flex: 10,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Text(widget.name), Text(widget.name),
Divider(), const Divider(),
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
height: 50, height: 50,
child: Container( child: Container(
color: Colors.blue, color: Colors.blue,
child: TextButton( child: TextButton(
onPressed: () {
DatePicker.showDateTimePicker(context,
minTime: minTime,
currentTime: eventTime,
maxTime: DateTime.now().add(const Duration(days: 365*10)),
onConfirm: (newEventTime) {
setState((){ eventTime = newEventTime; });
}
);
},
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Icon(FontAwesome5.calendar_alt, color: Colors.white), const Icon(FontAwesome5.calendar_alt, color: Colors.white),
SizedBox(width: 10), const SizedBox(width: 10),
Text(getDateFormat().format(this.eventTime), style: TextStyle(color: Colors.white, fontSize: 25)), Text(getDateFormat().format(eventTime), style: const TextStyle(color: Colors.white, fontSize: 25)),
] ]
), )
onPressed: () {
DatePicker.showDateTimePicker(context,
showTitleActions: true,
minTime: minTime,
currentTime: eventTime,
maxTime: DateTime.now().add(Duration(days: 365*10)),
onConfirm: (newEventTime) {
setState((){ this.eventTime = newEventTime; });
}
);
}
) )
) )
), ),
@ -294,10 +295,10 @@ class ConfirmPizzaEventState extends State<ConfirmPizzaEventDialog> {
child: Container( child: Container(
color: Colors.blue, color: Colors.blue,
child: TextButton( child: TextButton(
child: Text("Confirm", style: TextStyle(color: Colors.white)),
onPressed: () async { onPressed: () async {
Navigator.pop(context, this.eventTime); Navigator.pop(context, eventTime);
}, },
child: const Text("Confirm", style: TextStyle(color: Colors.white)),
) )
) )
) )