Skip to content

Commit

Permalink
added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
netharuM committed May 6, 2022
1 parent 7b5246b commit 992bd98
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 65 deletions.
25 changes: 23 additions & 2 deletions lib/db_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import 'package:path/path.dart';

class DBHandler {
DBHandler._init();

/// instance of the [DBHandler]
static final DBHandler instance = DBHandler._init();

static Database? _database;
Future<Database> get database async => _database ??= await _initDB();

/// initializes the [Database]
Future<Database> _initDB() async {
sqfliteFfiInit();
String pathToDb = await getApplicationDocumentsDirectory().then((dir) {
Expand All @@ -22,6 +25,7 @@ class DBHandler {
);
}

/// this will execute a sql commands to create the databases
Future<void> _onCreate(Database db, int version) async {
await db.execute('''
CREATE TABLE bells (
Expand All @@ -37,6 +41,8 @@ class DBHandler {
''');
}

/// returns bells as a [List] of [Map]s `List<Map<String, dynamic>>`
/// - this also sorts the bells by there position or order
Future<List<Map<String, dynamic>>> getBells() async {
final Database db = await database;
List<Map<String, dynamic>> map = [
Expand All @@ -47,14 +53,20 @@ class DBHandler {
return map;
}

/// inserts a [Bell] into the database
Future<int> insertBell(Bell bell) async {
final Database db = await database;
return await db.insert(
'bells', bell.toMap(boolToInt: true, listToString: true));
}

///
/// @param deactivate - enable or disable the process of deactivating bell when updating
/// updates a bell in the dataBase
/// - [bell] - a bell with updated parameters make sure that `id` is available in the bell
/// - lets say you wanna update the title of a bell
/// - ```dart
/// updateBell(someBell..title = "someNewTitle");
/// ```
/// - [dispose] - enable or disable the process of deactivating bell when updating
///
Future<int> updateBell(Bell bell, {bool dispose = true}) async {
final Database db = await database;
Expand All @@ -66,6 +78,7 @@ class DBHandler {
where: 'id = ?', whereArgs: [bell.id]);
}

/// moves a bell from a [prevPos] to a [newPos] in the dataBase
Future<void> moveBell(int prevPos, int newPos) async {
List<Map<String, dynamic>> bellMaps = await getBells();
prevPos = bellMaps[prevPos]['position'];
Expand All @@ -88,6 +101,13 @@ class DBHandler {
}
}

/// fixes the messed up bell positions
///
/// when you delete a bell bell there are gaps between bell positions - `[0,1,2,4,5]`
///
/// `3` is missing
///
/// this will fix the bell positions to `[0,1,2,3,4]`
Future<void> fixBellPositions() async {
List<Map<String, dynamic>> bellsMap = await getBells();
for (var i = 0; i < bellsMap.length; i++) {
Expand All @@ -98,6 +118,7 @@ class DBHandler {
}
}

/// deletes a [Bell]
Future<int> deleteBell(Bell bell) async {
final Database db = await database;
bell.deactivateBell();
Expand Down
3 changes: 3 additions & 0 deletions lib/inheited_widgets.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';

/// inherited widget for the [BellCard] this will provide data needed for [BellCard]
class BellCardData extends InheritedWidget {
const BellCardData({required this.shake, Key? key, required Widget child})
: super(child: child, key: key);

/// if [BellCard] needs to shake it needs to be [true] otherwise [false]
final bool shake;

/// picks the bellCardData from the [context]
static BellCardData of(BuildContext context) {
final BellCardData? result =
context.dependOnInheritedWidgetOfExactType<BellCardData>();
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class _MyAppState extends State<MyApp> with WindowListener {
}),
),
tooltipTheme: TooltipThemeData(
showDuration:
const Duration(), //setting the show duration to minimum as possible
decoration: BoxDecoration(
color: const Color(0xff32363d),
borderRadius: BorderRadius.circular(8),
Expand Down
5 changes: 3 additions & 2 deletions lib/models/bell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BellErrorExtended {

@override
bool operator ==(dynamic other) {
if (runtimeType != other.runtimeType) return false;
return error == other.error;
}
}
Expand Down Expand Up @@ -153,8 +154,8 @@ class Bell {
/// this will look at the week days before activating
///
/// so if you wanna force the activation set
/// - @param force to [true] its [false] by default
/// - @param disableTimer - disables the activation of the timer
/// - @param [force] to [true] its [false] by default
/// - @param [disableTimer] - disables the activation of the timer
Future<void> activateBell({
bool force = false,
bool disableTimer = false,
Expand Down
6 changes: 4 additions & 2 deletions lib/pages/bell_add_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class _AddNewBellPageState extends State<AddNewBellPage> {
bool _filled = false;
TimeOfDay? _time;

/// returns [true] if every parameter is filled
bool _checkFilled() {
if (_titleController.text == "") return false;
if (_time == null) return false;
return true;
}

/// looking for ability to save
void _checkForSave() {
setState(() {
_filled = _checkFilled();
Expand Down Expand Up @@ -76,7 +78,7 @@ class _AddNewBellPageState extends State<AddNewBellPage> {
),
Expanded(
child: TextField(
onChanged: (value) {
onChanged: (_) {
_checkForSave();
},
decoration: const InputDecoration(
Expand All @@ -99,7 +101,7 @@ class _AddNewBellPageState extends State<AddNewBellPage> {
),
Expanded(
child: TextField(
onChanged: (value) {
onChanged: (_) {
_checkForSave();
},
decoration: const InputDecoration(
Expand Down
20 changes: 18 additions & 2 deletions lib/pages/bell_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ class BellEditingPage extends StatefulWidget {
class _BellEditingPageState extends State<BellEditingPage> {
final TextEditingController _titleController = TextEditingController();
final TextEditingController _descController = TextEditingController();

/// if anything has changed
bool _changed = false;

/// whether everything is filled or not
bool _filled = true;

/// time of the [Bell]
late TimeOfDay? _time;

/// list of weekDays
late List<bool> _days;

/// audio path of the [Bell]
String? _audioPath;

/// returns [true] if every necessary is filled other wise [false]
bool _checkFilled() {
if (_titleController.text == "") return false;
if (_time == null) return false;
Expand All @@ -40,6 +51,7 @@ class _BellEditingPageState extends State<BellEditingPage> {
super.initState();
}

/// returns [true] if any parameter has changed otherwise [false]
bool _checkChanged() {
if (_titleController.text != (widget.bell.title ?? "")) return true;
if (_descController.text != (widget.bell.description ?? "")) return true;
Expand All @@ -49,6 +61,9 @@ class _BellEditingPageState extends State<BellEditingPage> {
return false;
}

/// checks for saving ability
/// - every thing needs to be filled in properly
/// - and atleast one parameter has to be changed
void _checkForSave() {
setState(() {
_changed = _checkChanged();
Expand Down Expand Up @@ -145,7 +160,7 @@ class _BellEditingPageState extends State<BellEditingPage> {
),
Expanded(
child: TextField(
onChanged: (value) {
onChanged: (_) {
_checkForSave();
},
decoration: const InputDecoration(
Expand All @@ -168,7 +183,7 @@ class _BellEditingPageState extends State<BellEditingPage> {
),
Expanded(
child: TextField(
onChanged: (value) {
onChanged: (_) {
_checkForSave();
},
keyboardType: TextInputType.multiline,
Expand Down Expand Up @@ -268,6 +283,7 @@ class _BellEditingPageState extends State<BellEditingPage> {
}
}

/// [AlertDialog] when user tries to go back without saving changes
AlertDialog confirmationDialog({Function()? onDiscard, Function()? onCancel}) {
return AlertDialog(
backgroundColor: Colors.black,
Expand Down
14 changes: 6 additions & 8 deletions lib/pages/bell_errors_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import 'package:auto_bell/widgets/title_bar.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class BellErrorsPage extends StatefulWidget {
/// shows errors of a [Bell]
/// - [bellErrors] errors of the [Bell]
class BellErrorsPage extends StatelessWidget {
/// errors of the [Bell]
final BellErrors bellErrors;
const BellErrorsPage({Key? key, required this.bellErrors}) : super(key: key);

@override
State<BellErrorsPage> createState() => _BellErrorsPageState();
}

class _BellErrorsPageState extends State<BellErrorsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -30,7 +28,7 @@ class _BellErrorsPageState extends State<BellErrorsPage> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Errors on bell "${widget.bellErrors.parent.title}"',
'Errors on bell "${bellErrors.parent.title}"',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
Expand Down Expand Up @@ -59,7 +57,7 @@ class _BellErrorsPageState extends State<BellErrorsPage> {
Expanded(
child: ListView(
children: [
for (var bellError in widget.bellErrors.getErrorsList)
for (var bellError in bellErrors.getErrorsList)
BellErrorWidget(
bellError: bellError,
),
Expand Down
Loading

0 comments on commit 992bd98

Please sign in to comment.