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

Commit

Permalink
Health Status (almost done)
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Nov 5, 2021
1 parent 728b727 commit 12bb2d6
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Mobile App to encourage reducing Food Wastes

This app is prototype of Food Busters as part of AIS Jump Thailand Hackathon

Prototype App with over 100K Bytes of Dart (Mostly Tab) and 4000 Lines of Code

The app is incomplete as it's only used to show our idea.

(Most data in this app are mocked up)
Expand Down
40 changes: 40 additions & 0 deletions lib/data/food_data.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "package:food_busters/data/delay.dart";
import "package:food_busters/models/health_record.dart";

Future<Map<String, double>> getOmeletData() async {
await serverRequest();
Expand All @@ -19,3 +20,42 @@ Future<Map<String, double>> getChickenRiceData() async {
"Protein": 30,
};
}

final Map<DateTime, HealthRecord> healthRecords = {
DateTime.utc(2021, 11, 5): HealthRecord(
nutrition: {
"Carbohydrate": 45,
"Fat": 25,
"Protein": 30,
},
breakfast: "-",
lunch: "Caesar Salad @ CP Best",
dinner: "Stir fried Thai basil and fried egg @ Aroi Cusine",
),
DateTime.utc(2021, 11, 6): HealthRecord(
nutrition: {
"Carbohydrate": 35,
"Fat": 35,
"Protein": 30,
},
breakfast: "Bread @ Rabbit House",
lunch: "Donut @ Kakyoin's Restaurant",
dinner: "-",
),
DateTime.utc(2021, 11, 7): HealthRecord(
nutrition: {
"Carbohydrate": 45,
"Fat": 15,
"Protein": 40,
},
breakfast: "-",
lunch: "Donut @ Rengoku's Restaurant",
dinner: "Stir fried Thai basil and fried egg @ Aroi Cusine",
),
};

Future<HealthRecord?> getHealthStat(DateTime date) async {
await serverRequest();

return healthRecords[date];
}
10 changes: 9 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,13 @@
"current_missions": "Current Missions",
"craving_missions": "Craving missions?",
"hard_missions_desc": "Attempt hard missions to get more awesome prices!",
"eat_less": "Eat less..."
"eat_less": "Eat less...",
"no_data_this_day": "No Data found for this day",
"recorded_menu": "Recorded Menu",
"breakfast": "Breakfast",
"lunch": "Lunch",
"dinner": "Dinner",
"easy_guide": "Easy Guide for you",
"guide_vegetable_header": "Left over VEGETABLE = METHANE",
"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!"
}
10 changes: 9 additions & 1 deletion lib/l10n/app_th.arb
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,13 @@
"current_missions": "ภารกิจที่กำลังทำอยู่",
"craving_missions": "กำลังมองหาภารกิจ?",
"hard_missions_desc": "ลองทำภารกิจที่ยากๆ เพื่อให้ได้ราคาที่คุ้มค่า!",
"eat_less": "กินสิ่งนี้ให้น้อยลง"
"eat_less": "กินสิ่งนี้ให้น้อยลง",
"no_data_this_day": "ไม่พบข้อมูลของวันนี้",
"recorded_menu": "เมนูที่บันทึกไว้",
"breakfast": "อาหารเช้า",
"lunch": "อาหารเที่ยง",
"dinner": "อาหารเย็น",
"easy_guide": "แนวทางง่ายๆสำหรับคุณ",
"guide_vegetable_header": "ผักที่กินเหลือ = มีเทน!",
"guide_vegetable_content": "ไม่ชอบผักใช่ไหม? หากคุณไม่ชอบผัก ให้บอกเชฟว่าอย่าใส่ผักมา เพราะ 30% ของอาหารเหลือคือผัก!"
}
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
Locale _locale =
// https://stackoverflow.com/questions/50923906/how-to-get-timezone-language-and-county-id-in-flutter-by-the-location-of-device
WidgetsBinding.instance?.window.locales[0] ?? const Locale("en");
WidgetsBinding.instance?.window.locales[0] ?? const Locale("en", "US");
Locale get locale => _locale;

late String _localeStr;
String get localeStrSimp => _localeStr.contains("th") ? "th" : "en";
Expand Down
14 changes: 14 additions & 0 deletions lib/models/health_record.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class HealthRecord {
Map<String, double> nutrition;

String breakfast;
String lunch;
String dinner;

HealthRecord({
required this.nutrition,
required this.breakfast,
required this.lunch,
required this.dinner,
});
}
2 changes: 2 additions & 0 deletions lib/styles/styles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ const rose = Color(0xFFF1D0C5);

const discordPfp =
"https://external-preview.redd.it/4PE-nlL_PdMD5PrFNLnjurHQ1QKPnCvg368LTDnfM-M.png?auto=webp&s=ff4c3fbc1cce1a1856cff36b5d2a40a6d02cc1c3";

const bold = TextStyle(fontWeight: FontWeight.w500);
142 changes: 142 additions & 0 deletions lib/views/record/health_status.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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/data/food_data.dart";
import "package:food_busters/models/health_record.dart";
import "package:food_busters/styles/styles.dart";
import "package:pie_chart/pie_chart.dart";
import "package:table_calendar/table_calendar.dart";

class HealthStatusPage extends StatefulWidget {
const HealthStatusPage({Key? key}) : super(key: key);
Expand All @@ -11,6 +15,17 @@ class HealthStatusPage extends StatefulWidget {
}

class _HealthStatusPageState extends State<HealthStatusPage> {
late DateTime selected;
late DateTime focused;

@override
void initState() {
super.initState();

final now = DateTime.now();
selected = focused = DateTime.utc(now.year, now.month, now.day);
}

@override
Widget build(BuildContext context) {
final text = AppLocalizations.of(context)!;
Expand All @@ -27,8 +42,135 @@ class _HealthStatusPageState extends State<HealthStatusPage> {
children: [
bgImage("clouds/bottom_aqua.png"),
bgImage("clouds/top_orange.png"),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 100.0,
horizontal: 24.0,
),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: calendar(),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: guide(text),
),
],
),
),
),
],
),
);
}

Widget calendar() => Container(
height: 305,
decoration: BoxDecoration(
color: lightGreen,
borderRadius: BorderRadius.circular(24.0),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TableCalendar(
focusedDay: focused,
firstDay: DateTime.utc(2021, 10, 1),
lastDay: DateTime.utc(2030, 12, 31),
availableCalendarFormats: const {CalendarFormat.month: "Month"},
daysOfWeekVisible: false,
rowHeight: 40,
selectedDayPredicate: (day) => isSameDay(day, selected),
onDaySelected: (newSelected, newFocused) {
if (isSameDay(focused, newFocused)) {
return;
}

setState(() {
selected = newSelected;
focused = newFocused;
});
},
),
),
);

Widget guide(AppLocalizations text) => Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12.0),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: FutureBuilder<HealthRecord?>(
future: getHealthStat(focused),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
final data = snapshot.data;
if (data == null) {
return Text(text.no_data_this_day);
} else {
return Column(
children: [
PieChart(
dataMap: data.nutrition,
chartType: ChartType.ring,
),
Text(
text.recorded_menu,
style: const TextStyle(fontWeight: FontWeight.w500),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
recordedMenu(text.breakfast, data.breakfast),
recordedMenu(text.lunch, data.lunch),
recordedMenu(text.dinner, data.dinner),
],
),
const SizedBox(height: 32),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: lightOrange,
borderRadius: BorderRadius.circular(4.0),
),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
text.easy_guide,
style: bold,
),
),
),
),
Row(
children: [
Image.asset(
"assets/images/foods/vegetable.png",
height: 70,
),
Text(text.guide_vegetable_header, style: bold),
],
),
Text(text.guide_vegetable_content),
],
);
}
} else {
return const Center(child: CircularProgressIndicator());
}
},
),
),
);

Widget recordedMenu(String meal, String data) => Text(
"$meal: $data",
textAlign: TextAlign.left,
);
}
8 changes: 7 additions & 1 deletion lib/views/record/record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "package:food_busters/main.dart";
import "package:food_busters/models/app_state.dart";
import "package:food_busters/models/food_record.dart";
import "package:food_busters/styles/styles.dart";
import "package:food_busters/views/record/health_status.dart";
import "package:food_busters/views/record/other_busters.dart";

class MyRecordPage extends StatefulWidget {
Expand Down Expand Up @@ -228,7 +229,12 @@ class _MyRecordPageState extends State<MyRecordPage> {
ElevatedButton(
onPressed: () {
if (state.isPremiumUser) {
// TODO smth
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const HealthStatusPage(),
),
);
} else {
showDialog(
context: context,
Expand Down
14 changes: 14 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1+1"
simple_gesture_detector:
dependency: transitive
description:
name: simple_gesture_detector
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -348,6 +355,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
table_calendar:
dependency: "direct main"
description:
name: table_calendar
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.3"
term_glyph:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 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.240+2400000
version: 1.0.260+2600000

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down Expand Up @@ -43,6 +43,7 @@ dependencies:
intl: ^0.17.0
flutter_toggle_tab: ^1.1.7
pie_chart: ^5.0.1
table_calendar: ^3.0.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 12bb2d6

Please sign in to comment.