added logic to save collections and display them
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../model/collection.dart';
|
||||
import '../service/storage.dart';
|
||||
import '../widgets/create_bookmark_collection_dialog.dart';
|
||||
|
||||
class CollectionsPage extends StatefulWidget {
|
||||
@@ -11,23 +13,36 @@ class CollectionsPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CollectionsPageState extends State<CollectionsPage> {
|
||||
final collections = Storage.loadCollections();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => showDialog(
|
||||
context: context,
|
||||
builder: (context) => CreateBookmarkCollectionDialog(),
|
||||
),
|
||||
onPressed: onAddButtonPressed,
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
body: ListView(),
|
||||
body: ListView.builder(
|
||||
itemBuilder: itemBuilder,
|
||||
itemCount: collections.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onAddButtonPressed() => showDialog(
|
||||
context: context,
|
||||
builder: (context) => CreateBookmarkCollectionDialog(),
|
||||
builder: (context) =>
|
||||
CreateBookmarkCollectionDialog(onSavePressed: onCollectionSaved),
|
||||
);
|
||||
|
||||
void onCollectionSaved(String name) {
|
||||
collections.add(Collection(name: name));
|
||||
setState(() {});
|
||||
Storage.saveCollections(collections);
|
||||
}
|
||||
|
||||
Widget itemBuilder(BuildContext context, int index) {
|
||||
return ListTile(title: Text(collections.elementAt(index).name));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user