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
65 changes: 21 additions & 44 deletions task_manager_app/lib/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,33 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:task_manager_app/model/todo_model.dart';
import 'package:task_manager_app/provider/todo_provider.dart';
import 'student_registration_screen.dart';

class HomePage extends StatelessWidget {
const HomePage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Task Manager'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.check_circle_outline,
size: 64,
color: Theme.of(context).colorScheme.primary,
),
const SizedBox(height: 16),
Text(
'Welcome to Group 1',
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 8),
Text(
'Week 2 – Your first Flutter app',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),

const SizedBox(height: 30),
final provider = context.watch<TodoProvider>();

// Student Registration Button
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const StudentRegistrationScreen(),
),
);
},
child: const Text('Student Registration form'),
),
],
return Scaffold(
appBar: AppBar(
title: const Text('Task Manager'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
),
);
body: provider.isLoading
? const Center(
child: CircularProgressIndicator(),
)
: ListView.builder(
itemCount: provider.todos.length,
itemBuilder: (context, index) {
final Todo todo = provider.todos[index];
return ListTile(
title: Text(todo.title),
);
},
));
}
}
7 changes: 6 additions & 1 deletion task_manager_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:task_manager_app/provider/todo_provider.dart';
import 'student_registration_screen.dart';
import 'home_page.dart';

void main() {
runApp(const TaskManagerApp());
runApp(ChangeNotifierProvider(
create: (_) => TodoProvider()..fetchAllTodos(),
child: const TaskManagerApp(),
));
}

class TaskManagerApp extends StatelessWidget {
Expand Down
32 changes: 32 additions & 0 deletions task_manager_app/lib/model/todo_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Todo {
final int userId;
final int id;
final String title;
final bool completed;

Todo({
required this.userId,
required this.id,
required this.title,
required this.completed,
});


factory Todo.fromJson(Map<String, dynamic> json) {
return Todo(
userId: json['userId'] as int,
id: json['id'] as int,
title: json['title'] as String,
completed: json['completed'] as bool,
);
}

Map<String, dynamic> toJson() {
return {
'userId': userId,
'id': id,
'title': title,
'completed': completed,
};
}
}
23 changes: 23 additions & 0 deletions task_manager_app/lib/provider/todo_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:task_manager_app/model/todo_model.dart';
import 'package:task_manager_app/service/api_service.dart';

class TodoProvider extends ChangeNotifier {
bool isLoading = false;
String errorMessage = "";
List<Todo> todos = [];

Future<List<Todo>> fetchAllTodos() async {
isLoading = true;
try {
todos = await ApiService().fetchAllTodos();
return todos;
} catch (e) {
errorMessage = e.toString();
return [];
} finally {
isLoading = false;
notifyListeners();
}
}
}
19 changes: 19 additions & 0 deletions task_manager_app/lib/service/api_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:dio/dio.dart';
import 'package:task_manager_app/model/todo_model.dart';

class ApiService {
final Dio dio =
Dio(BaseOptions(baseUrl: "https://jsonplaceholder.typicode.com/"));

Future<List<Todo>> fetchAllTodos() async {
final response = await dio.get("/todos?_limit=10");
if (response.statusCode == 200) {
final List<dynamic> data = response.data;
return data
.map((item) => Todo.fromJson(item as Map<String, dynamic>))
.toList();
} else {
throw Exception("Failed to load todos");
}
}
}
118 changes: 95 additions & 23 deletions task_manager_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
url: "https://pub.dev"
source: hosted
version: "1.4.1"
version: "1.4.0"
clock:
dependency: transitive
description:
Expand All @@ -49,6 +49,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
dio:
dependency: "direct main"
description:
name: dio
sha256: aff32c08f92787a557dd5c0145ac91536481831a01b4648136373cddb0e64f8c
url: "https://pub.dev"
source: hosted
version: "5.9.2"
dio_web_adapter:
dependency: transitive
description:
name: dio_web_adapter
sha256: "2f9e64323a7c3c7ef69567d5c800424a11f8337b8b228bad02524c9fb3c1f340"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
fake_async:
dependency: transitive
description:
Expand All @@ -75,30 +91,46 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: "direct main"
description:
name: http
sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
url: "https://pub.dev"
source: hosted
version: "1.6.0"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571"
url: "https://pub.dev"
source: hosted
version: "4.1.2"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
url: "https://pub.dev"
source: hosted
version: "11.0.2"
version: "10.0.9"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
url: "https://pub.dev"
source: hosted
version: "3.0.10"
version: "3.0.9"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "3.0.1"
lints:
dependency: transitive
description:
Expand All @@ -111,26 +143,42 @@ packages:
dependency: transitive
description:
name: matcher
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
url: "https://pub.dev"
source: hosted
version: "0.12.19"
version: "0.12.17"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
url: "https://pub.dev"
source: hosted
version: "0.13.0"
version: "0.11.1"
meta:
dependency: transitive
description:
name: meta
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
url: "https://pub.dev"
source: hosted
version: "1.16.0"
mime:
dependency: transitive
description:
name: mime
sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.0.0"
path:
dependency: transitive
description:
Expand All @@ -139,6 +187,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
provider:
dependency: "direct main"
description:
name: provider
sha256: "4e82183fa20e5ca25703ead7e05de9e4cceed1fbd1eadc1ac3cb6f565a09f272"
url: "https://pub.dev"
source: hosted
version: "6.1.5+1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -148,10 +204,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab"
sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c"
url: "https://pub.dev"
source: hosted
version: "1.10.2"
version: "1.10.1"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -188,26 +244,42 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
url: "https://pub.dev"
source: hosted
version: "0.7.4"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
url: "https://pub.dev"
source: hosted
version: "0.7.10"
version: "1.4.0"
vector_math:
dependency: transitive
description:
name: vector_math
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60"
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
url: "https://pub.dev"
source: hosted
version: "15.0.0"
web:
dependency: transitive
description:
name: web
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
url: "https://pub.dev"
source: hosted
version: "15.0.2"
version: "1.1.1"
sdks:
dart: ">=3.9.0-0 <4.0.0"
dart: ">=3.7.0-0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
3 changes: 3 additions & 0 deletions task_manager_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6
http: ^1.6.0
dio: ^5.9.2
provider: ^6.1.5+1

dev_dependencies:
flutter_test:
Expand Down
Loading
Loading