-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
741 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const kHiveSavedSchedule = "savedSchedule"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:hive/hive.dart'; | ||
|
||
import '../constants.dart'; | ||
|
||
class SavedScheduleProvider extends ChangeNotifier { | ||
final _box = Hive.box(kHiveSavedSchedule); | ||
|
||
/// oldName is needed to detect is schedule is renamed, | ||
/// if it is, the key with `oldName` will be deleted | ||
/// and a new schedule will be saved in the new key (`name`) | ||
void setSchedule( | ||
{required String name, required List<dynamic> data, String? oldName}) { | ||
if ((oldName != null) || (oldName == name)) _box.delete(oldName); | ||
_box.put(name, jsonEncode(data)); | ||
notifyListeners(); | ||
} | ||
|
||
Box get data => _box; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:albiruni/albiruni.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:hive/hive.dart'; | ||
|
||
import 'constants.dart'; | ||
import 'views/scheduler/schedule_layout.dart'; | ||
|
||
class SavedScheduleSelector extends StatefulWidget { | ||
const SavedScheduleSelector({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<SavedScheduleSelector> createState() => _SavedScheduleSelectorState(); | ||
} | ||
|
||
class _SavedScheduleSelectorState extends State<SavedScheduleSelector> { | ||
final box = Hive.box(kHiveSavedSchedule); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text( | ||
"Saved schedule", | ||
), | ||
systemOverlayStyle: SystemUiOverlayStyle.light | ||
.copyWith(statusBarColor: Colors.transparent), | ||
), | ||
body: ListView.builder( | ||
padding: const EdgeInsets.all(8), | ||
itemCount: box.length, | ||
itemBuilder: (context, index) { | ||
var name = box.keyAt(index); | ||
var data = box.getAt(index); | ||
return Card( | ||
child: ListTile( | ||
title: Text(name), | ||
trailing: IconButton( | ||
icon: const Icon( | ||
Icons.delete_outline, | ||
color: Colors.redAccent, | ||
), | ||
onPressed: () { | ||
showDialog( | ||
context: context, | ||
builder: (_) => AlertDialog( | ||
title: const Text("Confirm delete"), | ||
actions: [ | ||
OutlinedButton( | ||
onPressed: () => Navigator.pop(context), | ||
child: const Text("Cancel"), | ||
), | ||
ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
primary: Colors.redAccent), | ||
onPressed: () { | ||
Navigator.pop(context); | ||
setState(() => box.deleteAt(index)); | ||
}, | ||
child: const Text("Delete"), | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
), | ||
onTap: () async { | ||
List<dynamic> parsedListJson = jsonDecode(data); | ||
await Navigator.push( | ||
context, | ||
CupertinoPageRoute( | ||
builder: (_) => ScheduleLayout( | ||
initialName: name, | ||
subjects: List<Subject>.from( | ||
parsedListJson.map((e) => Subject.fromJson(e)), | ||
), | ||
), | ||
), | ||
); | ||
|
||
// refresh page when come back to thus screen | ||
setState(() {}); | ||
}, | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.