added some test stuff for gui elements
This commit is contained in:
parent
3d442140f9
commit
fa3142d666
2 changed files with 62 additions and 13 deletions
7
lib/entities/PlannedPizza.dart
Normal file
7
lib/entities/PlannedPizza.dart
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
class PlannedPizza {
|
||||||
|
final String name;
|
||||||
|
final DateTime dateTime;
|
||||||
|
|
||||||
|
PlannedPizza(this.name, this.dateTime);
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:pizzaplanner/entities/PlannedPizza.dart';
|
||||||
|
|
||||||
class PlannedPizzasPage extends StatefulWidget {
|
class PlannedPizzasPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
@ -7,27 +9,67 @@ class PlannedPizzasPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlannedPizzasState extends State<PlannedPizzasPage> {
|
class PlannedPizzasState extends State<PlannedPizzasPage> {
|
||||||
|
final List<PlannedPizza> plannedPizzas = <PlannedPizza>[
|
||||||
|
PlannedPizza("Movie Night", DateTime(2021, 6, 30)),
|
||||||
|
PlannedPizza("Birthday Pizza", DateTime(2021, 7, 14)),
|
||||||
|
PlannedPizza("Something else", DateTime(2021, 9, 3)),
|
||||||
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text("Planned Pizzas"),
|
title: Text("Planned Pizzas"),
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView.separated(
|
||||||
padding: const EdgeInsets.all(8),
|
padding: const EdgeInsets.all(8),
|
||||||
children: <Widget>[
|
itemCount: plannedPizzas.length,
|
||||||
Container(
|
itemBuilder: (BuildContext context, int i) {
|
||||||
height: 100,
|
return Container(
|
||||||
color: Colors.blueAccent,
|
height: 100,
|
||||||
child: const Center(child: Text("Pizza!"))
|
color: Colors.blueAccent,
|
||||||
)
|
child: PlannedPizzaWidget(plannedPizzas[i])
|
||||||
],
|
);
|
||||||
),
|
},
|
||||||
floatingActionButton: FloatingActionButton(
|
separatorBuilder: (BuildContext context, int i) => const Divider(),
|
||||||
onPressed: () => null,
|
|
||||||
tooltip: "Add Pizza",
|
|
||||||
child: Icon(Icons.add)
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlannedPizzaWidget extends StatelessWidget {
|
||||||
|
final DateFormat dateFormatter = DateFormat("yyyy-MM-dd");
|
||||||
|
final PlannedPizza plannedPizza;
|
||||||
|
|
||||||
|
PlannedPizzaWidget(this.plannedPizza);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context){
|
||||||
|
return Container(
|
||||||
|
height: 100,
|
||||||
|
color: Colors.blueAccent,
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
Text(plannedPizza.name),
|
||||||
|
Text(dateFormatter.format(plannedPizza.dateTime)),
|
||||||
|
Text(this.getTimeRemainingString())
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getTimeRemainingString(){
|
||||||
|
DateTime now = DateTime.now();
|
||||||
|
Duration duration = plannedPizza.dateTime.difference(now);
|
||||||
|
if (duration.inHours <= 0) {
|
||||||
|
return "In ${duration.inMinutes} minutes!";
|
||||||
|
}
|
||||||
|
if (duration.inDays <= 0) {
|
||||||
|
return "In ${duration.inHours} hours";
|
||||||
|
}
|
||||||
|
if (duration.inDays <= 31) {
|
||||||
|
return "In ${duration.inDays} days";
|
||||||
|
}
|
||||||
|
return "In ${(duration.inDays / 7).floor()} weeks";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue