Skip to content

Commit

Permalink
Merge pull request #89 from IamMuuo/anki
Browse files Browse the repository at this point in the history
Anki
  • Loading branch information
IamMuuo authored Oct 1, 2024
2 parents f5568e3 + 175cb20 commit 1db66fe
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 682 deletions.
10 changes: 5 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class Academia extends StatelessWidget {
useMaterial3: true,
colorSchemeSeed: Colors.amber,
),
// darkTheme: ThemeData(
// brightness: Brightness.dark,
// useMaterial3: true,
// colorSchemeSeed: Colors.amber,
// ),
darkTheme: ThemeData(
brightness: Brightness.dark,
useMaterial3: true,
colorSchemeSeed: Colors.amber,
),
home: Obx(
() => userController.isLoggedIn.value
? const LayoutPage()
Expand Down
1 change: 1 addition & 0 deletions lib/tools/anki/controllers/topic_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class TopicController extends GetxController {
for (final val in values) {
allTopics.add(AnkiTopic.fromJson(val));
}
update();
});
return allTopics;
}
Expand Down
16 changes: 14 additions & 2 deletions lib/tools/anki/pages/anki_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:academia/tools/anki/controllers/controllers.dart';
import 'package:get/get.dart';
import './empty_anki_home_screen.dart';
import './populated_anki_home_screen.dart';
import './create_topic_form.dart';

class AnkiHomePage extends StatelessWidget {
const AnkiHomePage({super.key});
Expand All @@ -16,12 +17,13 @@ class AnkiHomePage extends StatelessWidget {
resizeToAvoidBottomInset: false,
body: CustomScrollView(
slivers: [
const SliverAppBar(
SliverAppBar(
expandedHeight: 250,
backgroundColor: Theme.of(context).colorScheme.tertiaryContainer,
snap: true,
pinned: true,
floating: true,
flexibleSpace: FlexibleSpaceBar(
flexibleSpace: const FlexibleSpaceBar(
title: Text("Anki"),
),
),
Expand All @@ -34,6 +36,16 @@ class AnkiHomePage extends StatelessWidget {
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const CreateTopicForm(),
),
);
},
child: const Icon(Ionicons.add),
),
);
}
}
104 changes: 104 additions & 0 deletions lib/tools/anki/pages/create_topic_form.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'package:academia/tools/anki/controllers/controllers.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../models/models.dart';

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

@override
Widget build(BuildContext context) {
final TextEditingController titleController = TextEditingController();
final TextEditingController descController = TextEditingController();
final TopicController topicController = Get.find<TopicController>();

return Scaffold(
appBar: AppBar(
title: const Text(
"Create a topic",
),
),
body: SafeArea(
minimum: const EdgeInsets.symmetric(horizontal: 12),
child: SingleChildScrollView(
child: Column(
children: [
TextFormField(
maxLength: 20,
controller: titleController,
decoration: InputDecoration(
hintText: "Write a description for your topic",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4),
),
),
),
const SizedBox(height: 8),
TextFormField(
controller: descController,
maxLines: 10,
decoration: InputDecoration(
hintText: "Write a description for your topic",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(4),
),
),
),
const SizedBox(height: 22),
FilledButton(
onPressed: () {
if (titleController.text.trim().isEmpty ||
descController.text.trim().isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("All Above Fields are required"),
duration: Duration(seconds: 1),
),
);
} else if (titleController.text.trim().length <= 3) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Topic Length should be more than 2 characters"),
duration: Duration(seconds: 1),
),
);
} else if (descController.text.trim().length <= 12) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Desc Length should be more than 11 characters"),
duration: Duration(seconds: 1),
),
);
} else {
// create topic
AnkiTopic ankiTopic = AnkiTopic(
name: titleController.text,
desc: descController.text,
);
// add to database
if (topicController.numTopics() <= 5) {
ankiTopic.isFavourite = true;
}
topicController.addTopic(ankiTopic);

if (topicController.numTopics() < 5) {
// updating favourites
topicController.getAllFavourites();
}
// updating topic list and favorites
topicController.getAllTopics();
topicController.getAllFavourites();
Navigator.of(context).pop();
}
},
child: const Text("Create topic"),
)
],
),
),
),
);
}
}
Loading

0 comments on commit 1db66fe

Please sign in to comment.