Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- class HomePage extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- final NotesContainer Notes = new NotesContainer();
- return Scaffold(
- appBar: AppBar(
- centerTitle: true,
- title: Text('My Notes'),
- backgroundColor: Color.fromRGBO(223, 175, 117, 1),
- actions: <Widget>[
- IconButton(
- icon: Icon(Icons.add),
- onPressed: (){
- Notes.add()
- },
- )
- ],
- ),
- body: Notes
- );
- }
- }
- class NoteData{
- String title;
- String content;
- NoteData(this.title, this.content);
- NoteData.noContent(t){
- title = t;
- content ='';
- }
- }
- class NotesContainer extends StatefulWidget{
- @override
- State<StatefulWidget> createState(){
- return new _NotesContainer();
- }
- }
- class _NotesContainer extends State<NotesContainer>{
- final _notes = <NoteData>[new NoteData('title','thing to do'), new NoteData('title2','thing to do2')];
- void add({String title='1'}){ //just to test adding
- setState(() {
- _notes.add(new NoteData.noContent(title));
- });
- }
- Widget build(BuildContext context){
- return _buildNotesContainer();
- }
- _buildNotesContainer(){
- return new ListView.separated(
- itemCount: _notes.length,
- separatorBuilder: (BuildContext context, int index) => Divider(),
- itemBuilder: (BuildContext context, int index) {
- return ListTile(
- title: Text(_notes[index].title),
- );
- },
- padding: const EdgeInsets.all(10.0),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement