Skip to content

Instantly share code, notes, and snippets.

@chimon2000
Last active November 3, 2020 04:45
Show Gist options
  • Select an option

  • Save chimon2000/ad89d1656f4ce8164eafc7f086182a81 to your computer and use it in GitHub Desktop.

Select an option

Save chimon2000/ad89d1656f4ce8164eafc7f086182a81 to your computer and use it in GitHub Desktop.

Revisions

  1. chimon2000 revised this gist Nov 3, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions binder.page.dart
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,7 @@ class _BinderPageState extends State<BinderPage> {

    @override
    Widget build(BuildContext context) {
    // Subscribe to NotesState
    final state = context.watch(notesRef);

    return Scaffold(
    @@ -33,12 +34,16 @@ class _BinderPageState extends State<BinderPage> {
    children: [
    FlatButton(
    onPressed: () {
    // Get a reference of NotesViewLogic
    // and add a note.
    context.use(notesViewLogicRef).addNote();
    _controller.clear();
    },
    child: Text('Create Note')),
    TextField(
    controller: _controller,
    // Get a reference of NotesViewLogic
    // and update the input value.
    onChanged: (value) =>
    context.use(notesViewLogicRef).updateInput(value),
    decoration: InputDecoration.collapsed(hintText: 'Add a note'),
  2. chimon2000 created this gist Nov 1, 2020.
    58 changes: 58 additions & 0 deletions binder.page.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    class BinderPage extends StatefulWidget {
    const BinderPage({Key key}) : super(key: key);

    @override
    _BinderPageState createState() => _BinderPageState();
    }

    class _BinderPageState extends State<BinderPage> {
    TextEditingController _controller;

    @override
    void initState() {
    super.initState();

    _controller = TextEditingController();
    }

    @override
    void dispose() {
    _controller?.dispose();
    super.dispose();
    }

    @override
    Widget build(BuildContext context) {
    final state = context.watch(notesRef);

    return Scaffold(
    appBar: AppBar(title: Text('My notes app')),
    body: Padding(
    padding: const EdgeInsets.all(8.0),
    child: Column(
    children: [
    FlatButton(
    onPressed: () {
    context.use(notesViewLogicRef).addNote();
    _controller.clear();
    },
    child: Text('Create Note')),
    TextField(
    controller: _controller,
    onChanged: (value) =>
    context.use(notesViewLogicRef).updateInput(value),
    decoration: InputDecoration.collapsed(hintText: 'Add a note'),
    ),
    Divider(),
    Expanded(
    child: ListView.builder(
    itemBuilder: (context, index) => Note(text: state.notes[index]),
    itemCount: state.notes.length,
    ),
    )
    ],
    ),
    ),
    );
    }
    }