mirror of
https://github.com/johrpan/memor.git
synced 2025-10-28 19:27:25 +01:00
Initial commit
This commit is contained in:
commit
4be8aa8ff5
47 changed files with 1577 additions and 0 deletions
125
lib/memo_editor.dart
Normal file
125
lib/memo_editor.dart
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'memo.dart';
|
||||
import 'date_utils.dart';
|
||||
|
||||
/// A screen for editing or creating a memo.
|
||||
///
|
||||
/// The new memo will be returned when popping the navigator. A return value of
|
||||
/// null indicates that the user has canceled the editor.
|
||||
class MemoEditor extends StatefulWidget {
|
||||
/// The memo to edit.
|
||||
///
|
||||
/// A value of null indicates that the user will be creating a new memo.
|
||||
final Memo memo;
|
||||
|
||||
MemoEditor({
|
||||
this.memo,
|
||||
});
|
||||
|
||||
@override
|
||||
_MemoEditorState createState() => _MemoEditorState();
|
||||
}
|
||||
|
||||
class _MemoEditorState extends State<MemoEditor> {
|
||||
final _textController = TextEditingController();
|
||||
|
||||
DateTime _date;
|
||||
TimeOfDay _time;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.memo != null) {
|
||||
_textController.text = widget.memo.text;
|
||||
_date = widget.memo.scheduled.copy();
|
||||
_time = TimeOfDay.fromDateTime(_date);
|
||||
} else {
|
||||
_date = DateTime.now().add(Duration(days: 1));
|
||||
_time = TimeOfDay(
|
||||
hour: 8,
|
||||
minute: 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.memo != null ? 'Edit memo' : 'Add memo'),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text(
|
||||
widget.memo != null ? 'SAVE' : 'CREATE',
|
||||
style: theme.textTheme.button.copyWith(
|
||||
color: theme.colorScheme.onPrimary,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.pop(
|
||||
context,
|
||||
Memo(
|
||||
text: _textController.text,
|
||||
scheduled: _date.copyWithTime(_time),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: TextField(
|
||||
controller: _textController,
|
||||
maxLines: null,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: 'Memo',
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text('Date'),
|
||||
subtitle: Text(_date.dateString),
|
||||
onTap: () async {
|
||||
final result = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _date,
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime.now().add(Duration(days: 3560)),
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
setState(() {
|
||||
_date = result;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text('Time'),
|
||||
subtitle: Text(_time.format(context)),
|
||||
onTap: () async {
|
||||
final result = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: _time,
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
setState(() {
|
||||
_time = result;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue