Skip to content

Commit

Permalink
Refactoring (zachran-jidlo#17)
Browse files Browse the repository at this point in the history
* Refactoring - change quotes and indention

* Refactoring - move constants to shared directory

* Refactoring - extract OutlinedInputBorder as a constant

---------

Co-authored-by: Jakub Timko <[email protected]>
  • Loading branch information
Timmynek and Jakub Timko authored Feb 25, 2023
1 parent 615ce7a commit e9329a8
Show file tree
Hide file tree
Showing 25 changed files with 312 additions and 341 deletions.
13 changes: 6 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:zachranobed/constants.dart';
import 'package:zachranobed/models/user.dart';
import 'package:zachranobed/routes.dart';
import 'package:zachranobed/shared/constants.dart';

void main() {
runApp(const MyApp());
Expand All @@ -21,12 +21,11 @@ class MyApp extends StatelessWidget {
initialRoute: RouteManager.wrapper,
onGenerateRoute: RouteManager.generateRoute,
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(
primary: ZachranObedColors.primaryLight,
secondary: ZachranObedColors.primaryLight,
),
visualDensity: VisualDensity.adaptivePlatformDensity
),
colorScheme: ColorScheme.fromSwatch().copyWith(
primary: ZachranObedColors.primaryLight,
secondary: ZachranObedColors.primaryLight,
),
visualDensity: VisualDensity.adaptivePlatformDensity),
);
},
);
Expand Down
14 changes: 8 additions & 6 deletions lib/models/user.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import 'package:flutter/material.dart';

class User extends ChangeNotifier {

String internalId = "";
String email = "";
String password = "";
String pickUpFrom = "";
String internalId = '';
String email = '';
String password = '';
String pickUpFrom = '';

User.empty();

User.newUser({required this.internalId, required this.email, required this.pickUpFrom});
User.newUser(
{required this.internalId,
required this.email,
required this.pickUpFrom});

factory User.fromJson(Map<String, dynamic> json) {
return User.newUser(
Expand Down
104 changes: 57 additions & 47 deletions lib/constants.dart → lib/shared/constants.dart
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
import 'package:flutter/material.dart';

class ZachranObedColors {
static const primary = Color.fromRGBO(226, 16, 19, 1);
static const primaryLight = Color.fromRGBO(250, 71, 71, 1);
}

class ZachranObedStrings {
static const emailAddress = 'E-mailová adresa';
static const password = 'Heslo';
static const login = 'Přihlásit se';
static const logout = 'Odhlásit se';
static const forgottenPassword = 'Zapomněl/a jsem heslo';
static const rememberUser = 'Zapamatovat';
static const requiredFieldError = 'Vyplňte prosím toto pole';
static const requiredDropdownError = 'Vyberte prosím nějakou možnost';
static const overview = 'Přehled';
static const donations = 'Dary';
static const donationList = 'Seznam darů';
static const statistics = 'Statistiky';
static const menu = 'Menu';
static const change = 'Změnit';
static const youCanDonate = 'Dnes můžete darovat ještě';
static const youCantDonateAnymore = "Dnes již nemůžete darovat";
static const lastDonated = 'Naposledy darováno';
static const savedLunches = 'Zachráněno obědů';
static const borrowedBoxes = 'Zapůjčeno ReKrabiček';
static const offer = 'Nabídnout';
static const offerFood = 'Nabídnout pokrm';
static const offerWarmFood = 'Nabídnout teplý pokrm';
static const offerFoodDescription = 'Pokrm nabídnete darem charitativním organizacím, které jej předají lidem v nouzi.';
static const foodName = 'Název pokrmu';
static const allergens = 'Alergeny';
static const numberOfServings = 'Počet porcí';
static const packaging = 'Balení';
static const consumeBy = 'Spotřebujte do';
static const addAnotherFood = 'Přidat další pokrm';
static const confirmation = 'Pokrm jste \n úspěšně darovali \n \u2764 Děkujeme, že \n pomáháte.';
static const offerError = 'Nabídku se \n nepodařilo odeslat. \n \u274c Zkuste to prosím \n znovu.';
static const endOffer = 'Ukončit nabídku?';
static const cancelTheOffer = 'Zrušit změny';
static const continueTheOffer = 'Pokračovat v nabídce';
static const filter = 'Filtrovat';

static const zjLogoPath = 'assets/zj-logo.svg';
static const placeholderImagePath = 'assets/placeholder-image.png';
}
import 'package:flutter/material.dart';

class ZachranObedColors {
static const primary = Color.fromRGBO(226, 16, 19, 1);
static const primaryLight = Color.fromRGBO(250, 71, 71, 1);
}

class ZachranObedStrings {
static const emailAddress = 'E-mailová adresa';
static const password = 'Heslo';
static const login = 'Přihlásit se';
static const logout = 'Odhlásit se';
static const forgottenPassword = 'Zapomněl/a jsem heslo';
static const rememberUser = 'Zapamatovat';
static const requiredFieldError = 'Vyplňte prosím toto pole';
static const requiredDropdownError = 'Vyberte prosím nějakou možnost';
static const overview = 'Přehled';
static const donations = 'Dary';
static const donationList = 'Seznam darů';
static const statistics = 'Statistiky';
static const menu = 'Menu';
static const change = 'Změnit';
static const youCanDonate = 'Dnes můžete darovat ještě';
static const youCantDonateAnymore = 'Dnes již nemůžete darovat';
static const lastDonated = 'Naposledy darováno';
static const savedLunches = 'Zachráněno obědů';
static const borrowedBoxes = 'Zapůjčeno ReKrabiček';
static const offer = 'Nabídnout';
static const offerFood = 'Nabídnout pokrm';
static const offerWarmFood = 'Nabídnout teplý pokrm';
static const offerFoodDescription =
'Pokrm nabídnete darem charitativním organizacím, které jej předají lidem v nouzi.';
static const foodName = 'Název pokrmu';
static const allergens = 'Alergeny';
static const numberOfServings = 'Počet porcí';
static const packaging = 'Balení';
static const consumeBy = 'Spotřebujte do';
static const addAnotherFood = 'Přidat další pokrm';
static const confirmation =
'Pokrm jste \n úspěšně darovali \n \u2764 Děkujeme, že \n pomáháte.';
static const offerError =
'Nabídku se \n nepodařilo odeslat. \n \u274c Zkuste to prosím \n znovu.';
static const endOffer = 'Ukončit nabídku?';
static const cancelTheOffer = 'Zrušit změny';
static const continueTheOffer = 'Pokračovat v nabídce';
static const filter = 'Filtrovat';

static const zjLogoPath = 'assets/zj-logo.svg';
static const placeholderImagePath = 'assets/placeholder-image.png';
}

class WidgetStyle {
static const inputBorder = OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black),
borderRadius: BorderRadius.zero,
);
}
21 changes: 11 additions & 10 deletions lib/ui/screens/donated_food_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ class DonatedFoodDetail extends StatelessWidget {

@override
Widget build(BuildContext context) {

final offeredFood = ModalRoute.of(context)!.settings.arguments as OfferedFood;
final offeredFood =
ModalRoute.of(context)!.settings.arguments as OfferedFood;

return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text("Detail daru"),
title: const Text('Detail daru'),
),
body: Center(
child: Column(
children: <Widget>[
Text("Název pokrmu: ${offeredFood.name}"),
Text("Alergeny: ${offeredFood.allergens}"),
Text("Počet porcí: ${offeredFood.numberOfServings}"),
Text("Balení: ${offeredFood.packaging}"),
Text("Spotřebujte do: ${DateFormat('dd.MM.y HH:mm').format(offeredFood.consumeBy)}"),
Text("Číslo týdne: ${offeredFood.weekNumber}"),
Text("Id dárce: ${offeredFood.donorId}"),
Text('Název pokrmu: ${offeredFood.name}'),
Text('Alergeny: ${offeredFood.allergens}'),
Text('Počet porcí: ${offeredFood.numberOfServings}'),
Text('Balení: ${offeredFood.packaging}'),
Text(
'Spotřebujte do: ${DateFormat('dd.MM.y HH:mm').format(offeredFood.consumeBy)}'),
Text('Číslo týdne: ${offeredFood.weekNumber}'),
Text('Id dárce: ${offeredFood.donorId}'),
],
),
),
Expand Down
20 changes: 10 additions & 10 deletions lib/ui/screens/donations.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:zachranobed/constants.dart';
import 'package:zachranobed/custom_icons.dart';
import 'package:zachranobed/helpers/current_user.dart';
import 'package:zachranobed/helpers/current_week_number.dart';
import 'package:zachranobed/routes.dart';
import 'package:zachranobed/shared/constants.dart';
import 'package:zachranobed/ui/widgets/donated_food_list.dart';
import 'package:zachranobed/ui/widgets/floating_button.dart';

Expand All @@ -19,7 +19,7 @@ class Donations extends StatelessWidget {
actions: [
IconButton(
onPressed: () {
print('Kliknuto na "hledat"');
print('Kliknuto na hledat');
},
icon: const Icon(Icons.search),
),
Expand All @@ -34,30 +34,30 @@ class Donations extends StatelessWidget {
Row(
children: <Widget>[
ElevatedButton.icon(
icon: const Icon(CustomIcons.filter, size: 15.0,),
icon: const Icon(CustomIcons.filter, size: 15.0),
label: const Text(ZachranObedStrings.filter),
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
),
onPressed: () {
print("Kliknuto na filtrovat");
print('Kliknuto na filtrovat');
},
),
],
),
const SizedBox(height: 30),

DonatedFoodList(
itemsLimit: 3,
filter: 'cisloTydne(eq)${currentWeekNumber()},darce.id(eq)${getCurrentUser(context).internalId}',
filter:
'cisloTydne(eq)${currentWeekNumber()},darce.id(eq)${getCurrentUser(context).internalId}',
title: 'Tento týden',
showServingsSum: true,
),
const SizedBox(height: 30),

DonatedFoodList(
itemsLimit: 3,
filter: 'cisloTydne(eq)${currentWeekNumber() - 1},darce.id(eq)${getCurrentUser(context).internalId}',
filter:
'cisloTydne(eq)${currentWeekNumber() - 1},darce.id(eq)${getCurrentUser(context).internalId}',
title: 'Minulý týden',
showServingsSum: true,
),
Expand All @@ -66,9 +66,9 @@ class Donations extends StatelessWidget {
),
),
),

floatingActionButton: ZachranObedFloatingButton(
onPressed: () => Navigator.of(context).pushNamed(RouteManager.offerFood),
onPressed: () =>
Navigator.of(context).pushNamed(RouteManager.offerFood),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/screens/home.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:zachranobed/constants.dart';
import 'package:zachranobed/custom_icons.dart';
import 'package:zachranobed/shared/constants.dart';
import 'package:zachranobed/ui/screens/donations.dart';
import 'package:zachranobed/ui/screens/menu.dart';
import 'package:zachranobed/ui/screens/overview.dart';
Expand Down
Loading

0 comments on commit e9329a8

Please sign in to comment.