-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
185 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Aralan | ||
|
||
Homeschool tools | ||
Tools to keep track of daily homeschool activities. | ||
|
||
|
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,55 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../models/activity.dart'; | ||
|
||
class ActivityDialog extends StatefulWidget { | ||
final Activity activity; | ||
const ActivityDialog({Key? key, required this.activity}) : super(key: key); | ||
|
||
static Future<Activity?> open(BuildContext context, Activity activity) { | ||
return showDialog( | ||
context: context, | ||
builder: (context) => ActivityDialog(activity: activity), | ||
); | ||
} | ||
|
||
@override | ||
State<ActivityDialog> createState() => _ActivityDialogState(); | ||
} | ||
|
||
class _ActivityDialogState extends State<ActivityDialog> { | ||
late Activity activity; | ||
|
||
@override | ||
initState() { | ||
super.initState(); | ||
activity = widget.activity; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: const Text('Edit Activity'), | ||
content: TextFormField( | ||
autofocus: true, | ||
decoration: const InputDecoration(hintText: 'Enter activity name'), | ||
initialValue: activity.name, | ||
onChanged: (str) { | ||
setState(() { | ||
activity = activity.update(name: str); | ||
}); | ||
}, | ||
), | ||
actions: [ | ||
TextButton( | ||
onPressed: () => submit(context), | ||
child: const Text('SAVE'), | ||
), | ||
], | ||
); | ||
} | ||
|
||
void submit(BuildContext context) { | ||
Navigator.of(context).pop<Activity?>(activity); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:aralan/elements/activity_dialog.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import '../models/activity.dart'; | ||
|
||
typedef OnChangeActivity = void Function(Activity activity); | ||
|
||
class EditableActivityTile extends StatelessWidget { | ||
final Activity activity; | ||
final OnChangeActivity onChange; | ||
|
||
const EditableActivityTile({ | ||
Key? key, | ||
required this.activity, | ||
required this.onChange, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final theme = Theme.of(context); | ||
return ListTile( | ||
dense: true, | ||
title: Text( | ||
activity.name, | ||
style: theme.textTheme.headline4?.copyWith( | ||
fontWeight: FontWeight.normal, | ||
), | ||
), | ||
leading: IconButton( | ||
icon: const Icon(Icons.edit), | ||
onPressed: () async { | ||
final updated = await ActivityDialog.open(context, activity); | ||
if (updated != null) { | ||
onChange(updated); | ||
} | ||
}, | ||
), | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
List<T> reorder<T>(List<T> list, int indexBefore, int indexAfter) { | ||
final removed = list.removeAt(indexBefore); | ||
list.insert(indexAfter, removed); | ||
return list; | ||
} |
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,21 @@ | ||
import 'package:aralan/tools/reorder.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('reorder()', () { | ||
test('It should move 2nd element to first', () { | ||
final list = [1, 2, 3, 4]; | ||
expect(reorder(list, 1, 0), [2, 1, 3, 4]); | ||
}); | ||
|
||
test('It should move 3rd element to last', () { | ||
final list = [1, 2, 3, 4]; | ||
expect(reorder(list, 2, 3), [1, 2, 4, 3]); | ||
}); | ||
|
||
test('It should move last element to first', () { | ||
final list = [1, 2, 3, 4]; | ||
expect(reorder(list, 3, 0), [4, 1, 2, 3]); | ||
}); | ||
}); | ||
} |