Skip to content

Commit

Permalink
Merge pull request #112 from IamMuuo/courses
Browse files Browse the repository at this point in the history
Courses
  • Loading branch information
IamMuuo authored Dec 31, 2024
2 parents d6953f3 + 6beb84a commit 381288c
Show file tree
Hide file tree
Showing 46 changed files with 4,945 additions and 969 deletions.
11 changes: 10 additions & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:academia/features/auth/cubit/auth_cubit.dart';
import 'package:academia/database/database.dart';
import 'package:academia/features/features.dart';
import 'package:academia/utils/router/router.dart';
import 'package:flutter/material.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:google_fonts/google_fonts.dart';

class Academia extends StatelessWidget {
Expand All @@ -14,9 +16,16 @@ class Academia extends StatelessWidget {

@override
Widget build(BuildContext context) {
// Inject the application database
GetIt.instance.registerSingletonIfAbsent<AppDatabase>(
() => AppDatabase(),
instanceName: "cacheDB",
);
return MultiBlocProvider(
providers: [
BlocProvider(create: (_) => AuthCubit()),
BlocProvider(create: (_) => ProfileCubit()),
BlocProvider(create: (_) => CourseCubit()),
],
child: DynamicColorBuilder(
builder: (lightscheme, darkscheme) => MaterialApp.router(
Expand Down
27 changes: 9 additions & 18 deletions lib/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'dart:io';
import 'package:academia/features/auth/models/user.dart';
import 'package:academia/features/auth/models/user_credentials.dart';
import 'package:academia/features/auth/models/user_profile.dart';
import 'package:academia/features/courses/models/course.dart';
import 'package:academia/features/todo/models/todo.dart';
import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:drift_flutter/drift_flutter.dart';
Expand Down Expand Up @@ -43,7 +45,13 @@ Future<Directory> _getDatabaseDirectory() async {
}
}

@DriftDatabase(tables: [User, UserProfile, UserCredential])
@DriftDatabase(tables: [
User,
UserProfile,
UserCredential,
Course,
Todo,
])
class AppDatabase extends _$AppDatabase {
// After generating code, this class needs to define a schemaVersion getter
// and a constructor telling drift where the database should be stored.
Expand All @@ -61,20 +69,3 @@ class AppDatabase extends _$AppDatabase {
return driftDatabase(name: 'academia');
}
}

/// A singleton class to reference the local database.
/// Use this instead of AppDatabase to ensure you always
/// have an initialized instance
final class LocalDatabase {
static final LocalDatabase _instance = LocalDatabase._internal();

LocalDatabase._internal();

factory LocalDatabase() {
return _instance;
}

AppDatabase getInstance() {
return AppDatabase();
}
}
Loading

0 comments on commit 381288c

Please sign in to comment.