@@ -15,10 +15,12 @@ class NoteListPage extends StatefulWidget {
1515
1616class _NoteListPageState extends State <NoteListPage > {
1717 late AppDatabase database;
18+ int axisCount = 2 ;
1819 @override
1920 Widget build (BuildContext context) {
2021 database = Provider .of <AppDatabase >(context);
2122 return Scaffold (
23+ appBar: _getNoteListAppBar (),
2224 body: FutureBuilder <List <NoteData >>(
2325 future: _getNoteFromDatabase (),
2426 builder: (context, snapshot) {
@@ -97,7 +99,7 @@ class _NoteListPageState extends State<NoteListPage> {
9799 );
98100 },
99101 child: Container (
100- margin: const EdgeInsets .symmetric (vertical : 10 , horizontal: 10 ),
102+ margin: const EdgeInsets .symmetric (horizontal: 10 ),
101103 padding: const EdgeInsets .symmetric (horizontal: 10 , vertical: 10 ),
102104 decoration: BoxDecoration (
103105 borderRadius: BorderRadius .circular (5 ),
@@ -138,7 +140,9 @@ class _NoteListPageState extends State<NoteListPage> {
138140 ),
139141 );
140142 },
141- staggeredTileBuilder: (index) => StaggeredTile .fit (2 ),
143+ staggeredTileBuilder: (index) => StaggeredTile .fit (axisCount),
144+ mainAxisSpacing: 8 ,
145+ crossAxisSpacing: 4 ,
142146 );
143147 }
144148
@@ -178,4 +182,32 @@ class _NoteListPageState extends State<NoteListPage> {
178182 return Colors .yellow;
179183 }
180184 }
185+
186+ _getNoteListAppBar () {
187+ return AppBar (
188+ backgroundColor: Colors .white,
189+ centerTitle: true ,
190+ elevation: 0 ,
191+ title: Text (
192+ 'Notes' ,
193+ style: Theme .of (context).textTheme.headline5,
194+ ),
195+ actions: [
196+ IconButton (
197+ onPressed: () {
198+ if (axisCount == 2 ) {
199+ axisCount = 4 ;
200+ } else {
201+ axisCount = 2 ;
202+ }
203+ setState (() {});
204+ },
205+ icon: Icon (
206+ axisCount == 4 ? Icons .grid_on : Icons .list,
207+ color: Colors .black,
208+ ),
209+ )
210+ ],
211+ );
212+ }
181213}
0 commit comments