Skip to content

Commit

Permalink
Added OpenAI service to fetch macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Ketan Choyal committed Mar 15, 2024
1 parent b0ade66 commit caa40b1
Show file tree
Hide file tree
Showing 30 changed files with 2,330 additions and 1,010 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ firebase_app_id_file.json
GoogleService-Info.plist
.firebase/*
*.cache

keys.dart
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"dart.flutterSdkPath": "/Users/ketanchoyal/fvm/versions/stable",
"dart.flutterSdkPath": "~/fvm/versions/3.13.0",
}
2 changes: 1 addition & 1 deletion ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
13 changes: 13 additions & 0 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import 'package:calorie_tracker/core/services/firebase/firebase_service.dart';
import 'package:calorie_tracker/core/services/firebase/firebase_service.impl.dart';
import 'package:calorie_tracker/core/services/health/health_service.dart';
import 'package:calorie_tracker/core/services/health/health_service.impl.dart';
import 'package:calorie_tracker/core/services/open_ai/open_ai_serice.impl.dart';
import 'package:calorie_tracker/core/services/open_ai/open_ai_service.dart';
import 'package:calorie_tracker/core/services/openfood_api/openfood_api_service.dart';
import 'package:calorie_tracker/core/services/openfood_api/openfood_api_service.impl.dart';
import 'package:calorie_tracker/l10n/l10n.dart';
import 'package:calorie_tracker/ui/blocs/auth/auth_bloc.dart';
import 'package:calorie_tracker/ui/blocs/goals/goals_bloc.dart';
import 'package:calorie_tracker/ui/views/home/home.dart';
import 'package:calorie_tracker/ui/views/search_food_macro/bloc/search_food_macro.cubit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
Expand All @@ -35,6 +38,9 @@ class App extends StatelessWidget {
RepositoryProvider<OpenFoodAPIService>(
create: (context) => OpenFoodAPIServiceImpl(),
),
RepositoryProvider<OpenAIService>(
create: (context) => OpenAIServiceImpl()..init(),
),
RepositoryProvider<FirebaseAuthService>(
create: (context) => FirebaseAuthServiceImpl(),
),
Expand All @@ -57,6 +63,13 @@ class App extends StatelessWidget {
RepositoryProvider.of<FirebaseService>(context),
)..getGoals(),
),
BlocProvider<SearchMacroCubit>(
create: (context) => SearchMacroCubit(
openAIService: RepositoryProvider.of<OpenAIService>(context),
firebaseService:
RepositoryProvider.of<FirebaseService>(context),
),
)
],
child: const AppView(),
),
Expand Down
29 changes: 29 additions & 0 deletions lib/core/enums/serving_type.enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
enum ServingType {
hundreedGrams('100g'),
onePiece('1pc'),
oneCup('1cup'),
smallSized('small-sized'),
mediumSized('medium-sized'),
largeSized('large-sized');

final String value;

String get displayValue {
switch (this) {
case ServingType.hundreedGrams:
return '100 grams';
case ServingType.onePiece:
return '1 Piece';
case ServingType.oneCup:
return '1 Cup';
case ServingType.smallSized:
return 'Small Sized';
case ServingType.mediumSized:
return 'Medium Sized';
case ServingType.largeSized:
return 'Large Sized';
}
}

const ServingType(this.value);
}
72 changes: 38 additions & 34 deletions lib/core/models/food/food.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ part of 'food.dart';
T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');

/// @nodoc
mixin _$Food {
Expand Down Expand Up @@ -136,9 +136,10 @@ class _$FoodCopyWithImpl<$Res, $Val extends Food>
}

/// @nodoc
abstract class _$$_FoodCopyWith<$Res> implements $FoodCopyWith<$Res> {
factory _$$_FoodCopyWith(_$_Food value, $Res Function(_$_Food) then) =
__$$_FoodCopyWithImpl<$Res>;
abstract class _$$FoodImplCopyWith<$Res> implements $FoodCopyWith<$Res> {
factory _$$FoodImplCopyWith(
_$FoodImpl value, $Res Function(_$FoodImpl) then) =
__$$FoodImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
Expand All @@ -159,9 +160,10 @@ abstract class _$$_FoodCopyWith<$Res> implements $FoodCopyWith<$Res> {
}

/// @nodoc
class __$$_FoodCopyWithImpl<$Res> extends _$FoodCopyWithImpl<$Res, _$_Food>
implements _$$_FoodCopyWith<$Res> {
__$$_FoodCopyWithImpl(_$_Food _value, $Res Function(_$_Food) _then)
class __$$FoodImplCopyWithImpl<$Res>
extends _$FoodCopyWithImpl<$Res, _$FoodImpl>
implements _$$FoodImplCopyWith<$Res> {
__$$FoodImplCopyWithImpl(_$FoodImpl _value, $Res Function(_$FoodImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
Expand All @@ -179,7 +181,7 @@ class __$$_FoodCopyWithImpl<$Res> extends _$FoodCopyWithImpl<$Res, _$_Food>
Object? incredients = freezed,
Object? isRecipe = freezed,
}) {
return _then(_$_Food(
return _then(_$FoodImpl(
id: freezed == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -230,8 +232,8 @@ class __$$_FoodCopyWithImpl<$Res> extends _$FoodCopyWithImpl<$Res, _$_Food>

/// @nodoc
class _$_Food extends _Food {
_$_Food(
class _$FoodImpl extends _Food {
_$FoodImpl(
{this.id,
required this.name,
this.description,
Expand Down Expand Up @@ -284,10 +286,10 @@ class _$_Food extends _Food {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Food &&
other is _$FoodImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.description, description) ||
Expand Down Expand Up @@ -326,8 +328,8 @@ class _$_Food extends _Food {
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_FoodCopyWith<_$_Food> get copyWith =>
__$$_FoodCopyWithImpl<_$_Food>(this, _$identity);
_$$FoodImplCopyWith<_$FoodImpl> get copyWith =>
__$$FoodImplCopyWithImpl<_$FoodImpl>(this, _$identity);
}

abstract class _Food extends Food {
Expand All @@ -342,7 +344,7 @@ abstract class _Food extends Food {
final DateTime? dateTime,
final double? quantity,
final List<Food>? incredients,
final bool? isRecipe}) = _$_Food;
final bool? isRecipe}) = _$FoodImpl;
_Food._() : super._();

@override
Expand All @@ -369,7 +371,8 @@ abstract class _Food extends Food {
bool? get isRecipe;
@override
@JsonKey(ignore: true)
_$$_FoodCopyWith<_$_Food> get copyWith => throw _privateConstructorUsedError;
_$$FoodImplCopyWith<_$FoodImpl> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
Expand Down Expand Up @@ -432,21 +435,22 @@ class _$NutritionCopyWithImpl<$Res, $Val extends Nutrition>
}

/// @nodoc
abstract class _$$_NutritionCopyWith<$Res> implements $NutritionCopyWith<$Res> {
factory _$$_NutritionCopyWith(
_$_Nutrition value, $Res Function(_$_Nutrition) then) =
__$$_NutritionCopyWithImpl<$Res>;
abstract class _$$NutritionImplCopyWith<$Res>
implements $NutritionCopyWith<$Res> {
factory _$$NutritionImplCopyWith(
_$NutritionImpl value, $Res Function(_$NutritionImpl) then) =
__$$NutritionImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({double calories, double? fat, double? carbs, double? protein});
}

/// @nodoc
class __$$_NutritionCopyWithImpl<$Res>
extends _$NutritionCopyWithImpl<$Res, _$_Nutrition>
implements _$$_NutritionCopyWith<$Res> {
__$$_NutritionCopyWithImpl(
_$_Nutrition _value, $Res Function(_$_Nutrition) _then)
class __$$NutritionImplCopyWithImpl<$Res>
extends _$NutritionCopyWithImpl<$Res, _$NutritionImpl>
implements _$$NutritionImplCopyWith<$Res> {
__$$NutritionImplCopyWithImpl(
_$NutritionImpl _value, $Res Function(_$NutritionImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
Expand All @@ -457,7 +461,7 @@ class __$$_NutritionCopyWithImpl<$Res>
Object? carbs = freezed,
Object? protein = freezed,
}) {
return _then(_$_Nutrition(
return _then(_$NutritionImpl(
calories: null == calories
? _value.calories
: calories // ignore: cast_nullable_to_non_nullable
Expand All @@ -480,8 +484,8 @@ class __$$_NutritionCopyWithImpl<$Res>

/// @nodoc
class _$_Nutrition extends _Nutrition {
_$_Nutrition(
class _$NutritionImpl extends _Nutrition {
_$NutritionImpl(
{required this.calories,
required this.fat,
required this.carbs,
Expand All @@ -503,10 +507,10 @@ class _$_Nutrition extends _Nutrition {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Nutrition &&
other is _$NutritionImpl &&
(identical(other.calories, calories) ||
other.calories == calories) &&
(identical(other.fat, fat) || other.fat == fat) &&
Expand All @@ -520,16 +524,16 @@ class _$_Nutrition extends _Nutrition {
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_NutritionCopyWith<_$_Nutrition> get copyWith =>
__$$_NutritionCopyWithImpl<_$_Nutrition>(this, _$identity);
_$$NutritionImplCopyWith<_$NutritionImpl> get copyWith =>
__$$NutritionImplCopyWithImpl<_$NutritionImpl>(this, _$identity);
}

abstract class _Nutrition extends Nutrition {
factory _Nutrition(
{required final double calories,
required final double? fat,
required final double? carbs,
required final double? protein}) = _$_Nutrition;
required final double? protein}) = _$NutritionImpl;
_Nutrition._() : super._();

@override
Expand All @@ -542,6 +546,6 @@ abstract class _Nutrition extends Nutrition {
double? get protein;
@override
@JsonKey(ignore: true)
_$$_NutritionCopyWith<_$_Nutrition> get copyWith =>
_$$NutritionImplCopyWith<_$NutritionImpl> get copyWith =>
throw _privateConstructorUsedError;
}
Loading

0 comments on commit caa40b1

Please sign in to comment.