refactoring
This commit is contained in:
81
lib/pages/collections_list_page.dart
Normal file
81
lib/pages/collections_list_page.dart
Normal file
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../model/collection.dart';
|
||||
import '../service/bookmarks_provider.dart';
|
||||
import '../service/shared_link_provider.dart';
|
||||
import '../service/storage.dart';
|
||||
import '../widgets/create_bookmark_collection_dialog.dart';
|
||||
import 'collection_page.dart';
|
||||
|
||||
class CollectionsListPage extends StatefulWidget {
|
||||
const CollectionsListPage({super.key});
|
||||
static const String routeName = '/collections';
|
||||
|
||||
@override
|
||||
State<CollectionsListPage> createState() => _CollectionsListPageState();
|
||||
}
|
||||
|
||||
class _CollectionsListPageState extends State<CollectionsListPage> {
|
||||
final collections = Storage.loadCollections();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<SharedLinkProvider>();
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: onAddButtonPressed,
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
body: ListView.builder(
|
||||
itemBuilder: itemBuilder,
|
||||
itemCount: collections.length,
|
||||
),
|
||||
bottomSheet: provider.currentMapsLinkMetadata == null
|
||||
? null
|
||||
: BottomSheet(onClosing: () {}, builder: bottomSheetBuilder),
|
||||
);
|
||||
}
|
||||
|
||||
Widget bottomSheetBuilder(BuildContext context) {
|
||||
final titleTextFieldController = TextEditingController(
|
||||
text: context
|
||||
.read<SharedLinkProvider>()
|
||||
.currentMapsLinkMetadata!
|
||||
.placeName,
|
||||
);
|
||||
return SizedBox(
|
||||
height: 200,
|
||||
child: TextField(controller: titleTextFieldController),
|
||||
);
|
||||
}
|
||||
|
||||
void onAddButtonPressed() => showDialog(
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
CreateBookmarkCollectionDialog(onSavePressed: onCollectionSaved),
|
||||
);
|
||||
|
||||
void onCollectionSaved(String name) {
|
||||
collections.add(Collection(name: name));
|
||||
setState(() {});
|
||||
Storage.saveCollections(collections);
|
||||
}
|
||||
|
||||
Widget itemBuilder(BuildContext context, int index) {
|
||||
final collection = collections.elementAt(index);
|
||||
return ListTile(
|
||||
title: Text(collection.name),
|
||||
onTap: () {
|
||||
BookmarksProvider.selectedCollectionId = collection.id;
|
||||
Navigator.pushNamed(context, CollectionPage.routeName);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user