This file contains hidden or 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
class LinearColorPicker extends StatelessWidget { | |
Color _currColor(Note note) => note?.color ?? kDefaultNoteColor; | |
@override | |
Widget build(BuildContext context) { | |
Note note = Provider.of<Note>(context); | |
return SingleChildScrollView( | |
scrollDirection: Axis.horizontal, | |
child: Row( | |
children: kNoteColors.map((color) => InkWell( |
This file contains hidden or 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
showModalBottomSheet( | |
context: context, | |
backgroundColor: _noteColor, | |
builder: (context) => ChangeNotifierProvider.value( | |
value: _note, | |
child: Consumer<Note>( | |
builder: (_, note, __) => Container( | |
color: note.color ?? kDefaultNoteColor, // use the latest picked color | |
child: Column( | |
mainAxisSize: MainAxisSize.min, |
This file contains hidden or 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
class Note extends ChangeNotifier { | |
... | |
/// Update specified properties and notify the listeners | |
void updateWith({ | |
String title, | |
String content, | |
Color color, | |
NoteState state, | |
}) { | |
... |
This file contains hidden or 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
/// Callback before the user dismiss the editor | |
Future<dynamic> _onPop(String uid) => _isDirty | |
? saveToFireStore(uid, _note) | |
: Future.value(); |
This file contains hidden or 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
@override | |
Widget build(BuildContext context) { | |
final uid = Provider.of<CurrentUser>(context).data.uid; | |
return ChangeNotifierProvider.value( | |
value: _note, | |
child: Consumer<Note>( | |
builder: (_, __, ___) => Theme( | |
data: Theme.of(context).copyWith( | |
primaryColor: _noteColor, | |
... |
This file contains hidden or 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
/// Presses the FAB to create a new note | |
Widget _fab(BuildContext context) => FloatingActionButton( | |
... | |
onPressed: () => Navigator.pushNamed(context, '/note'), | |
); | |
/// Starts editing a note when tapped | |
void _onNoteTap(Note note) => | |
Navigator.pushNamed(context, '/note', arguments: { 'note': note }); |
This file contains hidden or 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
// The editor of a [Note], also shows every detail about a single note. | |
class NoteEditor extends StatefulWidget { | |
/// Create a [NoteEditor], | |
/// provides an existed [note] in edit mode, or `null` to create a new one. | |
const NoteEditor({Key key, this.note}) : super(key: key); | |
final Note note; | |
@override | |
State<StatefulWidget> createState() => _NoteEditorState(note); |
This file contains hidden or 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
class NotesGrid extends StatelessWidget { | |
final List<Note> notes; | |
final void Function(Note) onTap; | |
const NotesGrid({Key key, this.notes, this.onTap}) : super(key: key); | |
/// A static factory method can be used as a function reference | |
static NotesGrid create({Key key, this.notes, this.onTap}) => | |
NotesGrid(key: key, notes: notes, onTap: onTap); |
This file contains hidden or 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
/// Home screen, displays [Note] in a Grid or List. | |
class HomeScreen extends StatefulWidget { | |
@override | |
State<StatefulWidget> createState() => _HomeScreenState(); | |
} | |
class _HomeScreenState extends State<HomeScreen> { | |
bool _gridView = true; // `true` to show a Grid, otherwise a List. | |
@override |
This file contains hidden or 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
class Note { | |
final String id; | |
String title; | |
String content; | |
Color color; | |
NoteState state; | |
final DateTime createdAt; | |
DateTime modifiedAt; | |
/// Instantiates a [Note]. |