Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
1.0.100
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Oct 27, 2021
1 parent c24d325 commit b18a14c
Show file tree
Hide file tree
Showing 16 changed files with 319 additions and 124 deletions.
Binary file added assets/images/clouds/top_hybrid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/money.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions lib/components/exchange_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "package:flutter/material.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:food_busters/styles/styles.dart";

AlertDialog exchangeSuccess(AppLocalizations text, BuildContext context) =>
AlertDialog(
title: Text(text.exchange.toUpperCase(), textAlign: TextAlign.center),
backgroundColor: lightGreen,
content: Text(text.exchange_complete),
actions: [
TextButton(
child: Text(
text.window_close,
style: const TextStyle(
color: Colors.black,
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);

AlertDialog exchangeFailed(AppLocalizations text, BuildContext context) =>
AlertDialog(
title: Text(text.exchange.toUpperCase(), textAlign: TextAlign.center),
backgroundColor: rose,
content: Text(text.exchange_failed),
actions: [
TextButton(
child: Text(
text.window_close,
style: const TextStyle(
color: Colors.black,
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
6 changes: 6 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@
"after": "AFTER",
"scan_your_food": "Scan your Food",
"scan_result": "Scan Result",
"scan_before_title": "PERFECT!",
"scan_before_content": "Let's enjoy and don't forget to come back again after you finish eating.",
"back_to_home": "Back to Home Screen",
"you_have_eaten": "You have eaten",
"sp_only": " only",
"of_the_dish": "of the dish",
"oh_no": "Oh no!",
"wow": "Wow!",
"save_money_1": "WOULD BE SAVED",
"save_money_2": "If you have eaten all.",
"learn_more": "Learn more",
"pollution_produced": "Pollution produced is {pollution} grams of CO2!",
"points": "pts",
Expand All @@ -51,6 +56,7 @@
"no_data_found": "Sorry, no data found",
"exchange": "Exchange",
"exchange_complete": "Completed! Time to enjoy.",
"exchange_failed": "Exchange Failed, Please verify you have enough points",
"n_days_pass": "{n} days pass",
"press_to_exchange": "Press to Exchange",
"points_shop": "Points Shop",
Expand Down
6 changes: 6 additions & 0 deletions lib/l10n/app_th.arb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@
"logout": "ล็อกเอาท์",
"before": "ก่อนทาน",
"after": "หลังทาน",
"scan_before_title": "สุดยอด!",
"scan_before_content": "ได้เวลาอร่อย! และอย่าลืมกลับมาอีกครั้งหลังทานเสร็จแล้ว",
"back_to_home": "กลับไปยังหน้าจอหลัก",
"scan_your_food": "สแกนอาหารของคุณ",
"scan_result": "ผลลัพธ์การสแกน",
"you_have_eaten": "คุณได้กินไป",
"sp_only": "เพียงแค่",
"of_the_dish": "ของทั้งจาน",
"oh_no": "ไม่นะ!",
"wow": "ว้าว",
"save_money_1": "คือเงินที่สามารถประหยัดได้",
"save_money_2": "ถ้าคุณได้กินอาหารหมดจาน",
"learn_more": "เรียนรู้เพิ่มเติม",
"pollution_produced": "มลพิษที่เกิดขึ้นคือคาร์บอนไดออกไซต์ {pollution} กรัม!",
"points": "แต้ม",
Expand All @@ -51,6 +56,7 @@
"no_data_found": "ขออภัย ไม่พบข้อมูลดังกล่าว",
"exchange": "แลก",
"exchange_complete": "สำเร็จ! ได้เวลาอร่อย",
"exchange_failed": "การแลกล้มเหลว โปรดตรวจสอบว่าคุณมีแต้มเพียงพอ",
"n_days_pass": "{n} วัน",
"press_to_exchange": "กดเพื่อแลก",
"points_shop": "ร้านค้าแต้ม",
Expand Down
15 changes: 9 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:food_busters/models/app_state.dart";
import "package:food_busters/views/login.dart";
import "package:flutter_localizations/flutter_localizations.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
Expand Down Expand Up @@ -35,19 +36,21 @@ class _MyAppState extends State<MyApp> {
late String _localeStr;
String get localeStrSimp => _localeStr.contains("th") ? "th" : "en";

@override
void initState() {
super.initState();
_localeStr = _locale.toString();
}

void setLocale(String value) {
setState(() {
_localeStr = value;
_locale = Locale(value);
});
}

final state = AppState();

@override
void initState() {
super.initState();
_localeStr = _locale.toString();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
41 changes: 41 additions & 0 deletions lib/models/app_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import "package:camera/camera.dart";

class AppState {
// * Image Part
XFile? _imageBefore;
XFile? _imageAfter;

XFile? get imageBefore => _imageBefore;
bool get imageBeforeAvailable => _imageBefore != null;
XFile? get imageAfter => _imageAfter;
bool get imageAfterAvailable => _imageAfter != null;
bool get imageReady => imageBeforeAvailable && imageAfterAvailable;

void setImageBefore(XFile image) {
_imageBefore = image;
}

void deleteImageBefore() {
_imageBefore = null;
}

void setImageAfter(XFile image) {
_imageAfter = image;
}

// * Points Part
// ! Subjected to be change to server-based rather than local, ephemeral
int _points = 18;

int get points => _points;

void addPoints(int points) {
_points += points;
}

bool usePoints(int points) {
if (_points < points) return false;
_points -= points;
return true;
}
}
2 changes: 2 additions & 0 deletions lib/styles/styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ const lightOrange = Color(0xFFFFC068);
const lightGreen = Color(0xFFBBDFC8);
const green = Color(0xFF5DC7AB);
const tan = Color(0xFFF4E4D8);
const brown = Color(0xFF533F2C);
const rose = Color(0xFFF1D0C5);
37 changes: 15 additions & 22 deletions lib/views/points/exchange.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import "package:flutter/material.dart";
import "package:flutter_gen/gen_l10n/app_localizations.dart";
import "package:food_busters/components/background.dart";
import "package:food_busters/components/exchange_dialog.dart";
import "package:food_busters/data/dummy_restaurant.dart";
import "package:food_busters/main.dart";
import "package:food_busters/models/app_state.dart";
import "package:food_busters/models/restaurant_menu.dart";
import "package:food_busters/styles/styles.dart";
import "package:food_busters/utils/string.dart";
Expand All @@ -21,6 +24,7 @@ class _ExchangePageState extends State<ExchangePage> {
@override
Widget build(BuildContext context) {
final text = AppLocalizations.of(context)!;
final appState = MyApp.of(context).state;

return Scaffold(
backgroundColor: const Color(0xFFF4E4D8),
Expand All @@ -33,7 +37,7 @@ class _ExchangePageState extends State<ExchangePage> {
Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text("18 ${text.points}"),
child: Text("${appState.points} ${text.points}"),
),
),
],
Expand Down Expand Up @@ -62,7 +66,7 @@ class _ExchangePageState extends State<ExchangePage> {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: data.isNotEmpty
? foodList(data, text)
? foodList(data, text, appState)
: Center(
child: Text(
text.no_data_found,
Expand All @@ -83,7 +87,11 @@ class _ExchangePageState extends State<ExchangePage> {
);
}

Widget foodList(List<RestaurantMenu> data, AppLocalizations text) =>
Widget foodList(
List<RestaurantMenu> data,
AppLocalizations text,
AppState state,
) =>
ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
Expand Down Expand Up @@ -148,27 +156,12 @@ class _ExchangePageState extends State<ExchangePage> {
showDialog(
context: context,
builder: (context) {
// * Do Something
return AlertDialog(
title: Text(text.exchange.toUpperCase()),
content: Text(text.exchange_complete),
backgroundColor: const Color(0xFFBBDFC8),
actions: [
TextButton(
child: Text(
text.window_close,
style: const TextStyle(
color: Colors.black,
),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
return state.usePoints(res.price)
? exchangeSuccess(text, context)
: exchangeFailed(text, context);
},
);
setState(() {});
},
child: Text(text.exchange),
),
Expand Down
Loading

0 comments on commit b18a14c

Please sign in to comment.