Skip to content

Instantly share code, notes, and snippets.

View xinthink's full-sized avatar

Yingxin Wu xinthink

View GitHub Profile
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(
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,
class Note extends ChangeNotifier {
...
/// Update specified properties and notify the listeners
void updateWith({
String title,
String content,
Color color,
NoteState state,
}) {
...
/// Callback before the user dismiss the editor
Future<dynamic> _onPop(String uid) => _isDirty
? saveToFireStore(uid, _note)
: Future.value();
@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,
...
/// 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 });
// 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);
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);
/// 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
class Note {
final String id;
String title;
String content;
Color color;
NoteState state;
final DateTime createdAt;
DateTime modifiedAt;
/// Instantiates a [Note].