mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
favorites page
This commit is contained in:
208
lib/pages/favorites/side_bar.dart
Normal file
208
lib/pages/favorites/side_bar.dart
Normal file
@@ -0,0 +1,208 @@
|
||||
part of 'favorites_page.dart';
|
||||
|
||||
class _LeftBar extends StatefulWidget {
|
||||
const _LeftBar({this.favPage, this.onSelected, this.withAppbar = false});
|
||||
|
||||
final _FavoritesPageState? favPage;
|
||||
|
||||
final VoidCallback? onSelected;
|
||||
|
||||
final bool withAppbar;
|
||||
|
||||
@override
|
||||
State<_LeftBar> createState() => _LeftBarState();
|
||||
}
|
||||
|
||||
class _LeftBarState extends State<_LeftBar> implements FolderList {
|
||||
late _FavoritesPageState favPage;
|
||||
|
||||
var folders = <String>[];
|
||||
|
||||
var networkFolders = <String>[];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
favPage = widget.favPage ??
|
||||
context.findAncestorStateOfType<_FavoritesPageState>()!;
|
||||
favPage.folderList = this;
|
||||
folders = LocalFavoritesManager().folderNames;
|
||||
networkFolders = ComicSource.all()
|
||||
.where((e) => e.favoriteData != null)
|
||||
.map((e) => e.favoriteData!.key)
|
||||
.toList();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
right: BorderSide(
|
||||
color: context.colorScheme.outlineVariant,
|
||||
width: 0.6,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
if (widget.withAppbar)
|
||||
SizedBox(
|
||||
height: 56,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 8),
|
||||
const CloseButton(),
|
||||
const SizedBox(width: 8),
|
||||
Text("Folders".tl, style: ts.s18,),
|
||||
],
|
||||
),
|
||||
).paddingTop(context.padding.top),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: widget.withAppbar ? EdgeInsets.zero : EdgeInsets.only(top: context.padding.top),
|
||||
itemCount: folders.length + networkFolders.length + 2,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
const Icon(Icons.local_activity),
|
||||
const SizedBox(width: 8),
|
||||
Text("Local".tl),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
color: context.colorScheme.primary,
|
||||
onPressed: () {
|
||||
newFolder().then((value) {
|
||||
setState(() {
|
||||
folders = LocalFavoritesManager().folderNames;
|
||||
});
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
index--;
|
||||
if (index < folders.length) {
|
||||
return buildLocalFolder(folders[index]);
|
||||
}
|
||||
index -= folders.length;
|
||||
if (index == 0) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
const Icon(Icons.cloud),
|
||||
const SizedBox(width: 8),
|
||||
Text("Network".tl),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
index--;
|
||||
return buildNetworkFolder(networkFolders[index]);
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildLocalFolder(String name) {
|
||||
bool isSelected = name == favPage.folder && !favPage.isNetwork;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if (isSelected) {
|
||||
return;
|
||||
}
|
||||
favPage.setFolder(false, name);
|
||||
widget.onSelected?.call();
|
||||
},
|
||||
child: Container(
|
||||
height: 42,
|
||||
alignment: Alignment.centerLeft,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? context.colorScheme.primaryContainer.withOpacity(0.36)
|
||||
: null,
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
color:
|
||||
isSelected ? context.colorScheme.primary : Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.only(left: 16),
|
||||
child: Text(name),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildNetworkFolder(String key) {
|
||||
var data = getFavoriteDataOrNull(key);
|
||||
if (data == null) {
|
||||
return const SizedBox();
|
||||
}
|
||||
bool isSelected = key == favPage.folder && favPage.isNetwork;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if (isSelected) {
|
||||
return;
|
||||
}
|
||||
favPage.setFolder(true, key);
|
||||
widget.onSelected?.call();
|
||||
},
|
||||
child: Container(
|
||||
height: 42,
|
||||
alignment: Alignment.centerLeft,
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? context.colorScheme.primaryContainer.withOpacity(0.36)
|
||||
: null,
|
||||
border: Border(
|
||||
left: BorderSide(
|
||||
color:
|
||||
isSelected ? context.colorScheme.primary : Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.only(left: 16),
|
||||
child: Text(data.title),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void update() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void updateFolders() {
|
||||
setState(() {
|
||||
folders = LocalFavoritesManager().folderNames;
|
||||
networkFolders = ComicSource.all()
|
||||
.where((e) => e.favoriteData != null)
|
||||
.map((e) => e.favoriteData!.key)
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user