Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

.vscode
23 changes: 23 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
PODS:
- Flutter (1.0.0)
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- Flutter (from `Flutter`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78

PODFILE CHECKSUM: 4305caec6b40dde0ae97be1573c53de1882a07e5

COCOAPODS: 1.16.2
7 changes: 3 additions & 4 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
F06BB449B7F7E40DDF2EA4DA /* Pods-RunnerTests.release.xcconfig */,
6989FDD0423CD6426AD2CF04 /* Pods-RunnerTests.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -471,7 +470,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = YYRTDRLFNE;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -654,7 +653,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = YYRTDRLFNE;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -677,7 +676,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = YYRTDRLFNE;
DEVELOPMENT_TEAM = "";
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
41 changes: 37 additions & 4 deletions lib/features/todo/data/datasources/todo_remote_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import '../models/todo_dto.dart';
@injectable
class TodoRemoteDataSource {
final http.Client _client;
// TODO: Replace this with the URL we provide you
final String baseUrl = 'https://6825aa0f0f0188d7e72ddd9a.mockapi.io/api/v1';
final String baseUrl = 'https://68346d42464b49963602c7e1.mockapi.io';

TodoRemoteDataSource(this._client);

Expand All @@ -32,9 +31,18 @@ class TodoRemoteDataSource {
}
}

Future<TodoDTO> addTodo(String title) async {
Future<TodoDTO> addTodo(
String title,
String? description,
String? imageUrl,
) async {
try {
final newTodo = {'title': title, 'createdAtSeconds': DateTime.now().millisecondsSinceEpoch ~/ 1000};
final newTodo = {
'title': title,
'description': description,
'imageUrl': imageUrl,
'createdAtSeconds': DateTime.now().millisecondsSinceEpoch ~/ 1000,
};

log('Sending todo: ${json.encode(newTodo)}');

Expand All @@ -61,6 +69,31 @@ class TodoRemoteDataSource {
}
}

Future<TodoDTO> updateStatus(String id, bool isDone) async {
try {
final response = await _client.patch(
Uri.parse('$baseUrl/todo/$id'),
headers: {'Content-Type': 'application/json'},
body: json.encode({'isDone': isDone}),
);

log('Response status: ${response.statusCode}');
log('Response body: ${response.body}');

if (response.statusCode == 201 || response.statusCode == 200) {
final Map<String, dynamic> responseData = json.decode(response.body);

// If the API response is not in the expected format, transform it
return TodoDTO.fromJson(responseData);
} else {
throw Exception('Failed to toggle todo: ${response.statusCode}');
}
} catch (e) {
log('Error toggling todo: $e');
throw Exception('Failed to toggle todo: $e');
}
}

// For local client-side ID generation
String generateId() {
return const Uuid().v4();
Expand Down
6 changes: 5 additions & 1 deletion lib/features/todo/data/models/todo_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class TodoDTO with _$TodoDTO {
const factory TodoDTO({
required String id,
required String title,
required bool isDone,
String? description,
String? imageUrl,
int? createdAtSeconds,
}) = _TodoDTO;

factory TodoDTO.fromJson(Map<String, dynamic> json) => _$TodoDTOFromJson(json);
factory TodoDTO.fromJson(Map<String, dynamic> json) =>
_$TodoDTOFromJson(json);
}
92 changes: 88 additions & 4 deletions lib/features/todo/data/models/todo_dto.freezed.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lib/features/todo/data/models/todo_dto.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading