fixed linting warnings in the rest of the dart code

This commit is contained in:
broodjeaap89 2021-09-03 17:54:40 +02:00
parent ff2dd7b3d6
commit e388a7140e
7 changed files with 91 additions and 94 deletions

View file

@ -8,11 +8,11 @@ class PickPizzaRecipePage extends StatelessWidget {
Widget build(BuildContext context){ Widget build(BuildContext context){
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("Pick Pizza Recipe"), title: const Text("Pick Pizza Recipe"),
), ),
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Container( body: Container(
padding: EdgeInsets.fromLTRB(10, 10, 10, 10), padding: const EdgeInsets.all(16),
child: ValueListenableBuilder( child: ValueListenableBuilder(
valueListenable: Hive.box<PizzaRecipe>("PizzaRecipes").listenable(), valueListenable: Hive.box<PizzaRecipe>("PizzaRecipes").listenable(),
builder: (context, Box<PizzaRecipe> pizzaRecipesBox, widget) { builder: (context, Box<PizzaRecipe> pizzaRecipesBox, widget) {

View file

@ -18,7 +18,7 @@ import 'package:vibration/vibration.dart';
class PizzaEventNotificationPage extends StatefulWidget { class PizzaEventNotificationPage extends StatefulWidget {
final String? payload; final String? payload;
PizzaEventNotificationPage(this.payload); const PizzaEventNotificationPage(this.payload);
@override @override
PizzaEventNotificationState createState() => PizzaEventNotificationState(); PizzaEventNotificationState createState() => PizzaEventNotificationState();
@ -31,15 +31,14 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (this.widget.payload == null){ if (widget.payload == null){
print("Redirected to notification page but no payload... Popping");
Navigator.pop(context); Navigator.pop(context);
} }
var split = this.widget.payload!.split("__"); final split = widget.payload!.split("__");
var pizzaEventId = int.parse(split[0]); final pizzaEventId = int.parse(split[0]);
var recipeStepId = int.parse(split[1]); final recipeStepId = int.parse(split[1]);
var pizzaEventsBox = Hive.box<PizzaEvent>("PizzaEvents"); final pizzaEventsBox = Hive.box<PizzaEvent>("PizzaEvents");
pizzaEvent = pizzaEventsBox.get(pizzaEventId)!; pizzaEvent = pizzaEventsBox.get(pizzaEventId)!;
recipeStep = pizzaEvent.recipe.recipeSteps[recipeStepId]; recipeStep = pizzaEvent.recipe.recipeSteps[recipeStepId];
@ -59,11 +58,11 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("From notification"), title: const Text("From notification"),
), ),
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Container( body: Container(
padding: EdgeInsets.fromLTRB(40, 10, 40, 10), padding: const EdgeInsets.all(16),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
@ -78,61 +77,59 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
child: Text(recipeStep.name) child: Text(recipeStep.name)
), ),
), ),
Divider(), const Divider(),
Expanded( Expanded(
flex: 10, flex: 10,
child: Container( child: Container(
color: Colors.blue, color: Colors.blue,
width: double.infinity, width: double.infinity,
child: TextButton( child: TextButton(
child: Text("Ignore", style: TextStyle(color: Colors.white)),
onPressed: () async { onPressed: () async {
showDialog(context: context, builder: (BuildContext context) { showDialog(context: context, builder: (BuildContext context) {
return buildIgnoreDialog(); return buildIgnoreDialog();
}); });
}, },
child: const Text("Ignore", style: TextStyle(color: Colors.white)),
) )
) )
), ),
Divider(), const Divider(),
Expanded( Expanded(
flex: 30, flex: 30,
child: Container( child: Container(
color: Colors.blue, color: Colors.blue,
width: double.infinity, width: double.infinity,
child: TextButton( child: TextButton(
child: Text("Snooze 15 minutes", style: TextStyle(color: Colors.white)),
onPressed: () async { onPressed: () async {
setRecipeStepNotificatcion(DateTime.now().add(const Duration(minutes: 15))); setRecipeStepNotification(DateTime.now().add(const Duration(minutes: 15)));
Navigator.pop(context); Navigator.pop(context);
}, },
onLongPress: () async { onLongPress: () async {
var future5Min = DateTime.now().add(Duration(minutes: 5)); final future5Min = DateTime.now().add(const Duration(minutes: 5));
DatePicker.showDateTimePicker(context, DatePicker.showDateTimePicker(context,
showTitleActions: true,
minTime: future5Min, minTime: future5Min,
currentTime: future5Min, currentTime: future5Min,
maxTime: DateTime.now().add(Duration(days: 365*10)), maxTime: DateTime.now().add(const Duration(days: 365*10)),
onConfirm: (newEventTime) { onConfirm: (newEventTime) {
setState((){ setState((){
setRecipeStepNotificatcion(newEventTime); setRecipeStepNotification(newEventTime);
Navigator.pop(context); Navigator.pop(context);
}); });
} }
); );
}, },
child: const Text("Snooze 15 minutes", style: TextStyle(color: Colors.white)),
) )
) )
), ),
Divider(), const Divider(),
Expanded( Expanded(
flex: 40, flex: 40,
child: Container( child: Container(
color: Colors.blue, color: Colors.blue,
width: double.infinity, width: double.infinity,
child: TextButton( child: TextButton(
child: Text("Start!", style: TextStyle(color: Colors.white)),
onPressed: () async { onPressed: () async {
Navigator.pop(context); Navigator.pop(context);
Navigator.pushNamed( Navigator.pushNamed(
@ -144,6 +141,7 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
) )
); );
}, },
child: const Text("Start!", style: TextStyle(color: Colors.white)),
) )
) )
), ),
@ -162,17 +160,16 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
AlertDialog buildIgnoreDialog(){ AlertDialog buildIgnoreDialog(){
return AlertDialog( return AlertDialog(
title: Text("This step will be marked as completed."), title: const Text("This step will be marked as completed."),
content: Text("Instructions for this step can still be viewed on the Pizza Event page"), content: const Text("Instructions for this step can still be viewed on the Pizza Event page"),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text("Back"),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
}, },
child: const Text("Back"),
), ),
TextButton( TextButton(
child: Text("Complete"),
onPressed: () { onPressed: () {
setState(() { setState(() {
recipeStep.completeStepNow(); recipeStep.completeStepNow();
@ -181,12 +178,13 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
Navigator.pop(context); Navigator.pop(context);
Navigator.pop(context); Navigator.pop(context);
}, },
child: const Text("Complete"),
), ),
] ]
); );
} }
void setRecipeStepNotificatcion(DateTime newTime) async { Future<void> setRecipeStepNotification(DateTime newTime) async {
flutterLocalNotificationsPlugin.cancel(recipeStep.notificationId); flutterLocalNotificationsPlugin.cancel(recipeStep.notificationId);
const androidPlatformChannelSpecifics = AndroidNotificationDetails( const androidPlatformChannelSpecifics = AndroidNotificationDetails(
@ -205,7 +203,7 @@ class PizzaEventNotificationState extends State<PizzaEventNotificationPage> {
tz.TZDateTime.from(newTime, tz.local), tz.TZDateTime.from(newTime, tz.local),
platformChannelSpecific, platformChannelSpecific,
androidAllowWhileIdle: true, androidAllowWhileIdle: true,
payload: this.widget.payload, payload: widget.payload,
uiLocalNotificationDateInterpretation: uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime UILocalNotificationDateInterpretation.absoluteTime
); );

View file

@ -14,7 +14,7 @@ import 'package:url_launcher/url_launcher.dart';
class PizzaEventPage extends StatefulWidget { class PizzaEventPage extends StatefulWidget {
final PizzaEvent pizzaEvent; final PizzaEvent pizzaEvent;
PizzaEventPage(this.pizzaEvent); const PizzaEventPage(this.pizzaEvent);
@override @override
PizzaEventPageState createState() => PizzaEventPageState(); PizzaEventPageState createState() => PizzaEventPageState();
@ -24,76 +24,76 @@ class PizzaEventPageState extends State<PizzaEventPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var recipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.length; final recipeStepCount = widget.pizzaEvent.recipe.recipeSteps.length;
var completedRecipeStepCount = this.widget.pizzaEvent.recipe.recipeSteps.where((recipeStep) => recipeStep.completed).length; final completedRecipeStepCount = widget.pizzaEvent.recipe.recipeSteps.where((recipeStep) => recipeStep.completed).length;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(this.widget.pizzaEvent.name), title: Text(widget.pizzaEvent.name),
), ),
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
body: Container( body: Container(
padding: EdgeInsets.all(10), padding: const EdgeInsets.all(16),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
flex: 15, flex: 15,
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Text(this.widget.pizzaEvent.name), Text(widget.pizzaEvent.name),
Text(getTimeRemainingString(this.widget.pizzaEvent.dateTime)), Text(getTimeRemainingString(widget.pizzaEvent.dateTime)),
Container( Container(
color: Colors.blue, color: Colors.blue,
child: TextButton( child: TextButton(
child: Text(this.widget.pizzaEvent.recipe.name, style: TextStyle(color: Colors.white)),
onPressed: () { onPressed: () {
Navigator.pushNamed(context, "/event/recipe", arguments: this.widget.pizzaEvent); Navigator.pushNamed(context, "/event/recipe", arguments: widget.pizzaEvent);
}, },
child: Text(widget.pizzaEvent.recipe.name, style: const TextStyle(color: Colors.white)),
) )
) )
], ],
), ),
), ),
Divider(), const Divider(),
Expanded( Expanded(
flex: 80, flex: 80,
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
Center( const Center(
child: Text("Ingredients") child: Text("Ingredients")
), ),
Table( Table(
columnWidths: const <int, TableColumnWidth>{ columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(4), 0: FlexColumnWidth(4),
1: FlexColumnWidth(3), 1: FlexColumnWidth(3),
3: FlexColumnWidth(1), 3: FlexColumnWidth(),
}, },
children: <TableRow>[ children: <TableRow>[
TableRow( const TableRow(
children: <TableCell>[ children: <TableCell>[
TableCell(child: Text("Ingredient")), TableCell(child: Text("Ingredient")),
TableCell(child: Text("Total")), TableCell(child: Text("Total")),
TableCell(child: Center(child: Text("Bought"))) TableCell(child: Center(child: Text("Bought")))
] ]
) )
] + this.widget.pizzaEvent.recipe.ingredients.map((ingredient) => buildIngredientWidget(ingredient)).toList(), ] + widget.pizzaEvent.recipe.ingredients.map((ingredient) => buildIngredientWidget(ingredient)).toList(),
), ),
Table( Table(
columnWidths: const <int, TableColumnWidth>{ columnWidths: const <int, TableColumnWidth>{
0: FlexColumnWidth(4), 0: FlexColumnWidth(4),
1: FlexColumnWidth(3), 1: FlexColumnWidth(3),
2: FlexColumnWidth(1), 2: FlexColumnWidth(),
}, },
children: <TableRow>[ children: <TableRow>[
TableRow( TableRow(
children: <TableCell>[ children: <TableCell>[
TableCell(child: Text("Recipe Step")), const TableCell(child: Text("Recipe Step")),
TableCell(child: Text("When")), const TableCell(child: Text("When")),
TableCell(child: Text("$completedRecipeStepCount/$recipeStepCount")), TableCell(child: Text("$completedRecipeStepCount/$recipeStepCount")),
] ]
) )
] + this.widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStepWhenWidget(recipeStep)).toList() ] + widget.pizzaEvent.recipe.recipeSteps.map((recipeStep) => buildRecipeStepWhenWidget(recipeStep)).toList()
), ),
Divider(), const Divider(),
] ]
) )
), ),
@ -104,7 +104,7 @@ class PizzaEventPageState extends State<PizzaEventPage> {
} }
TableRow buildIngredientWidget(Ingredient ingredient){ TableRow buildIngredientWidget(Ingredient ingredient){
int totalWeight = this.widget.pizzaEvent.pizzaCount * this.widget.pizzaEvent.doughBallSize; final int totalWeight = widget.pizzaEvent.pizzaCount * widget.pizzaEvent.doughBallSize;
return TableRow( return TableRow(
children: <TableCell>[ children: <TableCell>[
TableCell(child: Text(ingredient.name)), TableCell(child: Text(ingredient.name)),
@ -113,7 +113,7 @@ class PizzaEventPageState extends State<PizzaEventPage> {
value: ingredient.bought, value: ingredient.bought,
onChanged: (bool? newValue) { onChanged: (bool? newValue) {
setState((){ingredient.bought = newValue!;}); setState((){ingredient.bought = newValue!;});
this.widget.pizzaEvent.save(); widget.pizzaEvent.save();
}, },
))), ))),
] ]

View file

@ -19,10 +19,10 @@ class PizzaEventsState extends State<PizzaEventsPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("Pizza Events"), title: const Text("Pizza Events"),
), ),
body: Container( body: Container(
padding: EdgeInsets.all(10), padding: const EdgeInsets.all(16),
child: ValueListenableBuilder( child: ValueListenableBuilder(
valueListenable: Hive.box<PizzaEvent>("PizzaEvents").listenable(), valueListenable: Hive.box<PizzaEvent>("PizzaEvents").listenable(),
builder: (context, Box<PizzaEvent> box, widget) { builder: (context, Box<PizzaEvent> box, widget) {
@ -46,13 +46,13 @@ class PizzaEventsState extends State<PizzaEventsPage> {
); );
if (newPizzaEvent != null){ if (newPizzaEvent != null){
this.addPizzaEvent(newPizzaEvent as PizzaEvent); addPizzaEvent(newPizzaEvent as PizzaEvent);
} }
}, },
tooltip: "Add Pizza Plans", tooltip: "Add Pizza Plans",
child: Center( child: Center(
child: Row( child: Row(
children: <Widget>[ children: const <Widget>[
Icon(Icons.add), Icon(Icons.add),
Icon(Icons.local_pizza_rounded), Icon(Icons.local_pizza_rounded),
] ]
@ -63,7 +63,7 @@ class PizzaEventsState extends State<PizzaEventsPage> {
} }
void addPizzaEvent(PizzaEvent pizzaEvent){ void addPizzaEvent(PizzaEvent pizzaEvent){
this.setState(() { setState(() {
pizzaEvents.add( pizzaEvents.add(
pizzaEvent pizzaEvent
); );

View file

@ -18,8 +18,8 @@ class RecipeStepInstructionPage extends StatefulWidget {
late final RecipeStep recipeStep; late final RecipeStep recipeStep;
RecipeStepInstructionPage(RecipeStepInstructionPageArguments arguments) { RecipeStepInstructionPage(RecipeStepInstructionPageArguments arguments) {
this.pizzaEvent = arguments.pizzaEvent; pizzaEvent = arguments.pizzaEvent;
this.recipeStep = arguments.recipeStep; recipeStep = arguments.recipeStep;
} }
@ -36,46 +36,46 @@ class RecipeStepInstructionState extends State<RecipeStepInstructionPage> {
void initState() { void initState() {
super.initState(); super.initState();
if (this.widget.recipeStep.subSteps.isNotEmpty) { if (widget.recipeStep.subSteps.isNotEmpty) {
this.currentSubStep = this.widget.recipeStep.subSteps.first; currentSubStep = widget.recipeStep.subSteps.first;
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var nextButtonText = "Start"; var nextButtonText = "Start";
if (this.page == this.widget.recipeStep.subSteps.length){ // -1 because of description page if (page == widget.recipeStep.subSteps.length){ // -1 because of description page
nextButtonText = "Finished"; nextButtonText = "Finished";
} else if (this.page > 0){ } else if (page > 0){
nextButtonText = "Next step"; nextButtonText = "Next step";
} }
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(this.widget.recipeStep.name), title: Text(widget.recipeStep.name),
), ),
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(
flex: 90, flex: 90,
child: PageView( child: PageView(
controller: this.controller, controller: controller,
onPageChanged: (newPage) => setState(() { onPageChanged: (newPage) => setState(() {
this.page = newPage; page = newPage;
if (this.widget.recipeStep.subSteps.isNotEmpty && this.page != 0) { if (widget.recipeStep.subSteps.isNotEmpty && page != 0) {
this.currentSubStep = this.widget.recipeStep.subSteps.elementAt(newPage-1); currentSubStep = widget.recipeStep.subSteps.elementAt(newPage-1);
} }
}), }),
children: <Widget>[ children: <Widget>[
Markdown( Markdown(
data: this.widget.recipeStep.description, data: widget.recipeStep.description,
onTapLink: (text, url, title) { onTapLink: (text, url, title) {
launch(url!); launch(url!);
}, },
) )
] + this.widget.recipeStep.subSteps.map((subStep) { ] + widget.recipeStep.subSteps.map((subStep) {
return Markdown( return Markdown(
data: subStep.description, data: subStep.description,
onTapLink: (text, url, title) { onTapLink: (text, url, title) {
@ -95,17 +95,17 @@ class RecipeStepInstructionState extends State<RecipeStepInstructionPage> {
width: double.infinity, width: double.infinity,
color: Colors.blue, color: Colors.blue,
child: TextButton( child: TextButton(
child: Text("Back", style: TextStyle(color: Colors.white)),
onPressed: () { onPressed: () {
if (page == 0){ if (page == 0){
return; return;
} }
if (this.currentSubStep != null){ if (currentSubStep != null){
this.currentSubStep?.completedOn = null; currentSubStep?.completedOn = null;
this.widget.pizzaEvent.save(); widget.pizzaEvent.save();
} }
this.controller.previousPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); controller.previousPage(duration: const Duration(milliseconds: 100), curve: Curves.ease);
}, },
child: const Text("Back", style: TextStyle(color: Colors.white)),
) )
) )
), ),
@ -119,19 +119,19 @@ class RecipeStepInstructionState extends State<RecipeStepInstructionPage> {
width: double.infinity, width: double.infinity,
color: Colors.blue, color: Colors.blue,
child: TextButton( child: TextButton(
child: Text(nextButtonText, style: TextStyle(color: Colors.white)),
onPressed: () { onPressed: () {
if (this.page == this.widget.recipeStep.subSteps.length){ if (page == widget.recipeStep.subSteps.length){
this.widget.recipeStep.completeStepNow(); widget.recipeStep.completeStepNow();
this.widget.pizzaEvent.save(); widget.pizzaEvent.save();
Navigator.pop(context); Navigator.pop(context);
return; return;
} else if (this.currentSubStep != null){ } else if (currentSubStep != null){
this.currentSubStep?.completeNow(); currentSubStep?.completeNow();
this.widget.pizzaEvent.save(); widget.pizzaEvent.save();
} }
this.controller.nextPage(duration: const Duration(milliseconds: 100), curve: Curves.ease); controller.nextPage(duration: const Duration(milliseconds: 100), curve: Curves.ease);
}, },
child: Text(nextButtonText, style: const TextStyle(color: Colors.white)),
) )
) )
), ),

View file

@ -5,11 +5,18 @@ import 'package:pizzaplanner/util.dart';
class PizzaEventWidget extends StatelessWidget { class PizzaEventWidget extends StatelessWidget {
final PizzaEvent pizzaEvent; final PizzaEvent pizzaEvent;
PizzaEventWidget(this.pizzaEvent); const PizzaEventWidget(this.pizzaEvent);
@override @override
Widget build(BuildContext context){ Widget build(BuildContext context){
return InkWell( return InkWell(
onTap: () {
Navigator.pushNamed(
context,
"/event/view",
arguments: pizzaEvent
);
},
child: Container( child: Container(
height: 120, height: 120,
color: Colors.blueAccent, color: Colors.blueAccent,
@ -34,7 +41,6 @@ class PizzaEventWidget extends StatelessWidget {
Expanded( Expanded(
child: IgnorePointer( child: IgnorePointer(
child: Slider( child: Slider(
min: 0.0,
max: pizzaEvent.recipe.recipeSteps.length.toDouble(), max: pizzaEvent.recipe.recipeSteps.length.toDouble(),
divisions: pizzaEvent.recipe.recipeSteps.length, divisions: pizzaEvent.recipe.recipeSteps.length,
value: pizzaEvent.recipe.getStepsCompleted().toDouble(), value: pizzaEvent.recipe.getStepsCompleted().toDouble(),
@ -59,13 +65,6 @@ class PizzaEventWidget extends StatelessWidget {
) )
) )
), ),
onTap: () {
Navigator.pushNamed(
context,
"/event/view",
arguments: this.pizzaEvent
);
},
); );
} }
} }

View file

@ -4,11 +4,14 @@ import 'package:pizzaplanner/entities/PizzaRecipe/pizza_recipe.dart';
class PizzaRecipeWidget extends StatelessWidget { class PizzaRecipeWidget extends StatelessWidget {
final PizzaRecipe pizzaRecipe; final PizzaRecipe pizzaRecipe;
PizzaRecipeWidget(this.pizzaRecipe); const PizzaRecipeWidget(this.pizzaRecipe);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return InkWell( return InkWell(
onTap: () {
Navigator.pushNamed(context, "/event/add", arguments: this.pizzaRecipe);
},
child: Container( child: Container(
height: 120, height: 120,
color: Colors.blueAccent, color: Colors.blueAccent,
@ -34,9 +37,6 @@ class PizzaRecipeWidget extends StatelessWidget {
) )
) )
), ),
onTap: () {
Navigator.pushNamed(context, "/event/add", arguments: this.pizzaRecipe);
},
); );
} }
} }