Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class HomePage extends StatelessWidget {
  4. @override
  5. Widget build(BuildContext context) {
  6. final NotesContainer Notes = new NotesContainer();
  7. return Scaffold(
  8. appBar: AppBar(
  9. centerTitle: true,
  10. title: Text('My Notes'),
  11. backgroundColor: Color.fromRGBO(223, 175, 117, 1),
  12. actions: <Widget>[
  13. IconButton(
  14. icon: Icon(Icons.add),
  15. onPressed: (){
  16. Notes.add()
  17. },
  18. )
  19. ],
  20. ),
  21. body: Notes
  22. );
  23. }
  24. }
  25.  
  26. class NoteData{
  27. String title;
  28. String content;
  29.  
  30. NoteData(this.title, this.content);
  31. NoteData.noContent(t){
  32. title = t;
  33. content ='';
  34. }
  35. }
  36.  
  37. class NotesContainer extends StatefulWidget{
  38. @override
  39.  
  40. State<StatefulWidget> createState(){
  41. return new _NotesContainer();
  42. }
  43.  
  44. }
  45.  
  46. class _NotesContainer extends State<NotesContainer>{
  47. final _notes = <NoteData>[new NoteData('title','thing to do'), new NoteData('title2','thing to do2')];
  48.  
  49. void add({String title='1'}){ //just to test adding
  50. setState(() {
  51. _notes.add(new NoteData.noContent(title));
  52. });
  53. }
  54.  
  55. Widget build(BuildContext context){
  56. return _buildNotesContainer();
  57. }
  58.  
  59. _buildNotesContainer(){
  60.  
  61. return new ListView.separated(
  62. itemCount: _notes.length,
  63. separatorBuilder: (BuildContext context, int index) => Divider(),
  64. itemBuilder: (BuildContext context, int index) {
  65. return ListTile(
  66. title: Text(_notes[index].title),
  67. );
  68. },
  69. padding: const EdgeInsets.all(10.0),
  70. );
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement