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
3 changes: 3 additions & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
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: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7

PODFILE CHECKSUM: 4305caec6b40dde0ae97be1573c53de1882a07e5

COCOAPODS: 1.16.2
2 changes: 2 additions & 0 deletions ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
Expand Down Expand Up @@ -54,6 +55,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
46 changes: 42 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://68346df6464b49963602cb3b.mockapi.io';

TodoRemoteDataSource(this._client);

Expand All @@ -32,9 +31,20 @@ 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,
'createdAtSeconds': DateTime.now().millisecondsSinceEpoch ~/ 1000
};

if (description != null) {
newTodo.addAll({'description': description});
}

if (imageUrl != null) {
newTodo.addAll({'imageUrl': imageUrl});
}
Comment on lines +36 to +47

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: You could have request body DTO with a to json method to avoid creating/parsing JSON directly here


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

Expand All @@ -61,6 +71,34 @@ class TodoRemoteDataSource {
}
}

Future<TodoDTO> updateTodo(String id, bool isDone) async {
try {
final updatedTodo = {'id': id, 'isDone': isDone};

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

final response = await _client.patch(
Uri.parse('$baseUrl/todo/$id'),
headers: {'Content-Type': 'application/json'},
body: json.encode({'id': id, '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);

return TodoDTO.fromJson(responseData);
} else {
throw Exception('Failed to create todo: ${response.statusCode}');
}
} catch (e) {
log('Error adding todo: $e');
throw Exception('Failed to create todo: $e');
}
}

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

Expand Down
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