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

Commit

Permalink
Finalizing March Version
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Mar 12, 2022
1 parent 36ac95c commit 77d076b
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 86 deletions.
11 changes: 9 additions & 2 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"save_money_2": "If you have eaten all.",
"swipe_hint": "Swipe Left or Right",
"learn_more": "Learn more",
"pollution_produced": "Pollution produced is {pollution} grams of CO2!",
"pollution_produced": "Pollution produced is {pollution} grams of CO₂!",
"your_data": "YOUR MEAL DATA",
"chart_desc": "Following Pie Chart represents calories in each nutrition category of meal",
"take_home_recommendation": "Take your leftover back home may be a good choice!",
Expand Down Expand Up @@ -111,5 +111,12 @@
"guide_vegetable_content": "Don't like vegetables? If you don't like it, tell chef to not put in becaus 30% of your food waste are vegetables!",
"cannot_share_loading": "You cannot share right now because it is loading or error occured",
"detected_by_sfc": "We automatically fill the menu for you from result of Smart Food Scanner 🌟✨ with confidence of",
"fun_fact": "Fun Fact"
"fun_fact": "Fun Fact",
"feedback_title": "Your Feedback Matters",
"feedback_content": "Do you want to do a survey about our prototype app? You can access survey at anytime using top-right actions in the home page.",
"not_now": "Not now",
"dont_ask_again": "Don't ask again",
"menu_co2": "This menu created {0} grams of CO₂",
"scan_share": "Check out my fabolous feasting out!\nMenu: {menu}, Ate {percent}% of the dish amd gained total of {calories} calories!\n",
"scan_share_certified": "This meal is also certified green and clean by Food Busters!"
}
7 changes: 6 additions & 1 deletion lib/l10n/app_th.arb
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,10 @@
"guide_vegetable_content": "ไม่ชอบผักใช่ไหม? หากคุณไม่ชอบผัก ให้บอกเชฟว่าอย่าใส่ผักมา เพราะ 30% ของอาหารเหลือคือผัก!",
"cannot_share_loading": "คุณไม่สามารถแชร์ได้ตอนนี้ เนื่องจากกำลังโหลดอยู่หรือมีข้อผิดพลาดเกินขึ้น",
"detected_by_sfc": "เราได้เติมเมนูของคุณโดยอัตโนมัติจากผลการสแกนของ Smart Food Scanner 🌟✨ ด้วยความมั่นใจที่",
"fun_fact": "เกร็ดน่ารู้"
"fun_fact": "เกร็ดน่ารู้",
"feedback_title": "ข้อเสนอแนะของคุณสำคัญ",
"feedback_content": "คุณต้องการที่จะทำแบบสอบถามการใช้งานแอพโปรโตไทป์หรือไม่? คุณสามารถเข้าถึงแบบสอบถามได้ตลอด โดยการกดปุ่มตรงมุมขวาบนของหน้าโฮม",
"not_now": "ยังไม่ใช่ตอนนี้",
"dont_ask_again": "อย่าถามอีก",
"menu_co2": "อาหารเมนูนี้สร้างคาร์บอนไดออกไซต์ {0} กรัม"
}
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class _MyAppState extends State<MyApp> {
Locale get locale => _locale;
late String _localeStr;

/// Either "en" or "th"
/// Either `"en"` or `"th"`
String get localeStrSimp => _localeStr.contains("th") ? "th" : "en";

void setLocale(String value) {
Expand All @@ -75,7 +75,7 @@ class _MyAppState extends State<MyApp> {
});
}

void resetLocale({bool doSetState = false}) {
void resetLocale() {
// https://stackoverflow.com/questions/50923906/how-to-get-timezone-language-and-county-id-in-flutter-by-the-location-of-device

if (state.language != null) {
Expand All @@ -88,7 +88,7 @@ class _MyAppState extends State<MyApp> {
_localeStr = _locale.toString();
state.language = _localeStr;

if (doSetState) setState(() {});
setState(() {});
}

AppState get state => Hive.box<AppState>(boxName).getAt(0)!;
Expand Down
8 changes: 8 additions & 0 deletions lib/models/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class AppState extends HiveObject {
save();
}

@HiveField(6, defaultValue: 4)
int _askForFeedback = 4;
int get askForFeedback => _askForFeedback;
set askForFeedback(int value) {
_askForFeedback = value;
save();
}

// * Most of getters and setters is automatically filled by GitHub Copilot✨✨

bool get imageBeforeAvailable => imageBefore != null;
Expand Down
1 change: 1 addition & 0 deletions lib/styles/styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const green = Color(0xFF5DC7AB);
const tan = Color(0xFFF4E4D8);
const brown = Color(0xFF533F2C);
const rose = Color(0xFFF1D0C5);
const meguRose = Color(0xFF8B1A15);

const bold = TextStyle(fontWeight: FontWeight.w500);

Expand Down
173 changes: 100 additions & 73 deletions lib/views/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,15 @@ class _HomePageState extends State<HomePage> {
Expanded(
flex: 1,
child: smallBtn(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MyPoints(),
),
);
},
onPressed: feedbackGoto(() => const MyPoints()),
content: t.my_points,
assetName: "points.webp",
),
),
Expanded(
flex: 1,
child: smallBtn(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MyRecordPage(),
),
);
},
onPressed: feedbackGoto(() => const MyRecordPage()),
content: t.my_record,
assetName: "record.webp",
),
Expand All @@ -183,29 +169,15 @@ class _HomePageState extends State<HomePage> {
Expanded(
flex: 1,
child: smallBtn(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const MyMissionPage(),
),
);
},
onPressed: feedbackGoto(() => const MyMissionPage()),
content: t.mission,
assetName: "mission.webp",
),
),
Expanded(
flex: 1,
child: smallBtn(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LeaderboardPage(),
),
);
},
onPressed: feedbackGoto(() => const LeaderboardPage()),
content: t.leaderboard,
assetName: "leaderboard.webp",
),
Expand All @@ -215,48 +187,103 @@ class _HomePageState extends State<HomePage> {
]);
}

Widget bigBtn({
required void Function() onPressed,
required String content,
required double padding,
required String assetName,
}) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: onPressed,
child: n.Row([
Image.asset("assets/images/icons/$assetName", height: 50),
n.Text(content)..fontSize = 26,
])
..mainCenter,
style: ElevatedButton.styleFrom(
padding: EdgeInsets.all(padding),
primary: lightOrange,
minimumSize: const Size(275, 0),
),
),
);
void Function() feedbackGoto(Widget Function() page) {
return () async {
await Navigator.push(
context,
MaterialPageRoute(builder: (context) => page()),
);

final appState = MyApp.of(context).state;
final t = useTranslation(context);
appState.askForFeedback--;

if (appState.askForFeedback <= 0) {
await showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: lightGreen,
title: n.Text(t.feedback_title)
..center
..freezed,
content: n.Text(t.feedback_content)
..center
..freezed,
actionsAlignment: MainAxisAlignment.center,
actions: [
n.Column([
n.Button(const Text("✨OK✨"))
..onPressed = () {
appState.askForFeedback = 0xffffffff;
launch(feedbackUrl);
Navigator.pop(context);
}
..center
..style = (n.ButtonStyle()..foregroundColor = brown),
n.Button(Text(t.not_now))
..onPressed = () {
appState.askForFeedback = 5;
Navigator.pop(context);
}
..style = (n.ButtonStyle()..foregroundColor = meguRose),
n.Button(Text(t.dont_ask_again))
..onPressed = () {
appState.askForFeedback = 0xffffffff;
Navigator.pop(context);
}
..style = (n.ButtonStyle()..foregroundColor = meguRose),
])
..center
..freezed,
],
),
);
}
};
}
}

Widget smallBtn({
required void Function() onPressed,
required String content,
required String assetName,
}) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: onPressed,
child: n.Column([
Image.asset("assets/images/icons/$assetName", height: 50),
n.Text(content)..fontSize = 14,
]),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(15),
primary: lightGreen,
),
Padding bigBtn({
required void Function() onPressed,
required String content,
required double padding,
required String assetName,
}) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: onPressed,
child: n.Row([
Image.asset("assets/images/icons/$assetName", height: 50),
n.Text(content)..fontSize = 26,
])
..mainCenter,
style: ElevatedButton.styleFrom(
padding: EdgeInsets.all(padding),
primary: lightOrange,
minimumSize: const Size(275, 0),
),
);
}
),
);
}

Padding smallBtn({
required void Function() onPressed,
required String content,
required String assetName,
}) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: onPressed,
child: n.Column([
Image.asset("assets/images/icons/$assetName", height: 50),
n.Text(content)..fontSize = 14,
]),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(15),
primary: lightGreen,
),
),
);
}
24 changes: 19 additions & 5 deletions lib/views/scan/scanafter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class _ScanAfterPageState extends State<ScanAfterPage> {
int pointRecieved = 0;
Map<String, double> foodData = {"undefined": 100};
double pollution = 0;
double totalCalories = 0;
MLAPIResult? apiResult;
Quote? quote;
int successedPromise = 0;
Expand Down Expand Up @@ -88,6 +89,11 @@ class _ScanAfterPageState extends State<ScanAfterPage> {
pollution = apiResult!.foodNutrition.pollution;
foodData = apiResult!.foodNutrition.toJson();
foodData.remove("pollution");

foodData.forEach((key, value) {
totalCalories += value;
});

successedPromise++;
}

Expand Down Expand Up @@ -222,10 +228,14 @@ class _ScanAfterPageState extends State<ScanAfterPage> {
}

await Share.share(
"Check my fabulous feasting out!\n"
"Menu: ${apiResult!.foodName.get(context)}, "
"Ate $percent% of the dish!\n"
"This meal is also certified green and clean.",
t.scan_share
.replaceFirst("{menu}", apiResult!.foodName.get(context))
.replaceFirst("{percent}", "$percent")
.replaceFirst(
"{calories}",
"${(percent * totalCalories / 100).round()}",
) +
(percent > 80 ? t.scan_share_certified : ""),
);
},
),
Expand Down Expand Up @@ -311,12 +321,16 @@ class _ScanAfterPageState extends State<ScanAfterPage> {
centerText: apiResult?.foodName.get(context),
),
),
n.Text(t.menu_co2.replaceFirst("{0}", "$pollution"))
..center
..w500
..freezed,
n.Text(
"${t.detected_by_sfc} "
"${(apiResult!.confidence * 100).toStringAsFixed(2)}%",
)
..center
..w500
..w600
..freezed,
n.Text(t.take_home_recommendation)
..center
Expand Down
2 changes: 1 addition & 1 deletion lib/views/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class _SettingsPageState extends State<SettingsPage> {
title: Text(t.reset_settings),
onTap: () async {
await Hive.box<AppState>(boxName).putAt(0, AppState());
MyApp.of(context).resetLocale(doSetState: true);
MyApp.of(context).resetLocale();
logOut();
},
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.407
version: 1.0.412

environment:
sdk: ">=2.16.0 <3.0.0"
Expand Down

0 comments on commit 77d076b

Please sign in to comment.