Skip to content

Commit

Permalink
image_view: make header floating on portrait
Browse files Browse the repository at this point in the history
  • Loading branch information
resucutie committed Oct 13, 2024
1 parent 81bafda commit 9ab0956
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 131 deletions.
123 changes: 70 additions & 53 deletions lib/views/navigation/image_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,74 @@ class ImageViewShell extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: ListTile(
contentPadding: EdgeInsets.zero,
title: const Text("Image", style: TextStyle(fontSize: 20.0)),
subtitle: Text("ID ${image.id}", style: const TextStyle(fontSize: 14.0)),
),
leading: BackButton(
onPressed: context.pop,
),
actions: [
IconButton(
icon: const Icon(Icons.edit),
tooltip: "Edit image",
onPressed: () async => context.push("/manage_image", extra: PresetManageImageSendable(await PresetImage.fromExistingImage(image)))
),
PopupMenuButton(
// child: Icon(Icons.more_vert),
itemBuilder: (context) {
return [
...booruItems(),
const PopupMenuDivider(),
...imageShareItems(image),
const PopupMenuDivider(),
...imageManagementItems(image, context: context, doulbeExitOnDelete: true)
];
}
)
],
bottom: collections != null ? PreferredSize(
preferredSize: Size.fromHeight(40.0 * collections!.length),
child: Column(
children: collections!.map((collection) => CollectionSwitcher(collection: collection, image: image,)).toList(),
)
) : null,
final Widget appBarTitle = ListTile(
contentPadding: EdgeInsets.zero,
title: const Text("Image", style: TextStyle(fontSize: 20.0)),
subtitle: Text("ID ${image.id}", style: const TextStyle(fontSize: 14.0)),
);
final Widget appBarLeading = BackButton(
onPressed: context.pop,
);
final List<Widget> appBarActions = [
IconButton(
icon: const Icon(Icons.edit),
tooltip: "Edit image",
onPressed: () async => context.push("/manage_image", extra: PresetManageImageSendable(await PresetImage.fromExistingImage(image)))
),
body: ScrollConfiguration(
behavior: const MaterialScrollBehavior().copyWith(
dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch, PointerDeviceKind.trackpad, PointerDeviceKind.stylus},
),
child: OrientationBuilder(
builder: (context, orientation) {
if(orientation == Orientation.portrait) {
return ListView(
children: [
PopupMenuButton(
// child: Icon(Icons.more_vert),
itemBuilder: (context) {
return [
...booruItems(),
const PopupMenuDivider(),
...imageShareItems(image),
const PopupMenuDivider(),
...imageManagementItems(image, context: context, doulbeExitOnDelete: true)
];
}
)
];
final PreferredSizeWidget? appBarBottom = (collections != null && collections!.isNotEmpty) ? PreferredSize(
preferredSize: Size.fromHeight(40.0 * collections!.length),
child: Column(
children: collections!.map((collection) => CollectionSwitcher(collection: collection, image: image,)).toList(),
)
) : null;
return OrientationBuilder(
builder: (context, orientation) {
if(orientation == Orientation.portrait) {
return CustomScrollView(
slivers: [
SliverAppBar(
title: appBarTitle,
leading: appBarLeading,
actions: appBarActions,
bottom: appBarBottom,
pinned: true,
floating: appBarBottom != null,
// snap: true,
),
SliverList(
delegate: SliverChildListDelegate([
if(shouldShowImageOnPortrait) ImageViewDisplay(image),
child
],
);
} else {
return Row(
])
)
],
);
} else {
return Scaffold(
appBar: AppBar(
title: appBarTitle,
leading: appBarLeading,
actions: appBarActions,
bottom: appBarBottom,
),
body: ScrollConfiguration(
behavior: const MaterialScrollBehavior().copyWith(
dragDevices: {PointerDeviceKind.mouse, PointerDeviceKind.touch, PointerDeviceKind.trackpad, PointerDeviceKind.stylus},
),
child: Row(
children: [
Expanded(
child: ImageViewDisplay(image)
Expand All @@ -100,11 +117,11 @@ class ImageViewShell extends StatelessWidget {
)

],
);
}
},
),
),
)
),
);
}
},
);
}
}
Expand Down
198 changes: 120 additions & 78 deletions lib/views/test_playground.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,86 +37,128 @@ class _TestPlaygroundScreenState extends State<TestPlaygroundScreen> {
debugPrint("End of test");
}

@override
Widget build(context) {
return Scaffold(
appBar: AppBar(
title: const Text("Playground"),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Wrap(
spacing: 8,
children: List.filled(5, Image.asset("assets/Screenshot_1009.webp", width: 64, fit: BoxFit.contain, filterQuality: FilterQuality.none,))
)
),
// MultipleImage(images: List.filled(3, const AssetImage("assets/Screenshot_1009.webp"))),
const StyleCounter(number: 1234567890, display: "squares",),
const StyleCounter(number: 1234567890, display: "baba",),
const StyleCounter(number: 1234567890, display: "signs",),
FilledButton(
onPressed: testAccurateIdentification,
child: const Text("test webcrawing"),
),
FilledButton(
child: const Text("test read collection"),
onPressed: () async {
final booru = await getCurrentBooru();
final collection = await booru.getCollection("0");
debugPrint("${collection?.name} ${collection?.id} ${collection?.pages}");
// @override
// Widget build(context) {
// return Scaffold(
// appBar: AppBar(
// title: const Text("Playground"),
// ),
// body: Column(
// crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// Center(
// child: Wrap(
// spacing: 8,
// children: List.filled(5, Image.asset("assets/Screenshot_1009.webp", width: 64, fit: BoxFit.contain, filterQuality: FilterQuality.none,))
// )
// ),
// // MultipleImage(images: List.filled(3, const AssetImage("assets/Screenshot_1009.webp"))),
// const StyleCounter(number: 1234567890, display: "squares",),
// const StyleCounter(number: 1234567890, display: "baba",),
// const StyleCounter(number: 1234567890, display: "signs",),
// FilledButton(
// onPressed: testAccurateIdentification,
// child: const Text("test webcrawing"),
// ),
// FilledButton(
// child: const Text("test read collection"),
// onPressed: () async {
// final booru = await getCurrentBooru();
// final collection = await booru.getCollection("0");
// debugPrint("${collection?.name} ${collection?.id} ${collection?.pages}");

final foundCollection = await booru.obtainMatchingCollection("1");
debugPrint("${foundCollection.map((e) => e.name)}");
},
),
FilledButton(
child: const Text("test write collection"),
onPressed: () async {
final booru = await getCurrentBooru();
// final foundCollection = await booru.obtainMatchingCollection("1");
// debugPrint("${foundCollection.map((e) => e.name)}");
// },
// ),
// FilledButton(
// child: const Text("test write collection"),
// onPressed: () async {
// final booru = await getCurrentBooru();

// creation
final extracted = await insertCollection(PresetCollection(
name: "Created collection",
pages: ["0", "1"]
));
final idCollection = extracted.id;
BooruCollection? collection = await booru.getCollection(idCollection);
debugPrint("${collection?.pages}");
// // creation
// final extracted = await insertCollection(PresetCollection(
// name: "Created collection",
// pages: ["0", "1"]
// ));
// final idCollection = extracted.id;
// BooruCollection? collection = await booru.getCollection(idCollection);
// debugPrint("${collection?.pages}");

// override
await insertCollection(PresetCollection(
id: idCollection,
name: "Created collection",
pages: ["1", "3"]
));
collection = await booru.getCollection(idCollection);
debugPrint("${collection?.pages}");
// // override
// await insertCollection(PresetCollection(
// id: idCollection,
// name: "Created collection",
// pages: ["1", "3"]
// ));
// collection = await booru.getCollection(idCollection);
// debugPrint("${collection?.pages}");

// deletion
await removeCollection(idCollection);
collection = await booru.getCollection(idCollection);
debugPrint("$collection");
},
),
FilledButton(
child: const Text("test write collection"),
onPressed: () async {
VirtualPresetCollection.urlToPreset("https://e926.net/pools/42095");
},
),
],
)
// body: AspectRatio(
// aspectRatio: 1,
// child: FractionallySizedBox(
// widthFactor: 0.5,
// heightFactor: 0.5,
// child: MultipleImage(images: List.filled(3, const AssetImage("assets/Screenshot_1009.webp")))
// )
// ),
);
}
// // deletion
// await removeCollection(idCollection);
// collection = await booru.getCollection(idCollection);
// debugPrint("$collection");
// },
// ),
// FilledButton(
// child: const Text("test write collection"),
// onPressed: () async {
// VirtualPresetCollection.urlToPreset("https://e926.net/pools/42095");
// },
// ),
// ],
// )
// // body: AspectRatio(
// // aspectRatio: 1,
// // child: FractionallySizedBox(
// // widthFactor: 0.5,
// // heightFactor: 0.5,
// // child: MultipleImage(images: List.filled(3, const AssetImage("assets/Screenshot_1009.webp")))
// // )
// // ),
// );
// }

@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
SliverAppBar(
pinned: true, // Keeps the AppBar at the top
floating: false,
expandedHeight: 200.0,
flexibleSpace: FlexibleSpaceBar(
// Title stays pinned and visible
title: Text('Title Stays'),
centerTitle: true,
),
// The bottom widget, which disappears first
bottom: PreferredSize(
preferredSize: Size.fromHeight(80), // Height of bottom widget
child: Container(
color: Colors.orangeAccent,
height: 80,
child: Center(
child: Text(
'Bottom Widget',
style: TextStyle(color: Colors.white, fontSize: 24),
),
),
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => ListTile(
title: Text('Item #$index'),
),
childCount: 30,
),
),
],
),
);
}
}

0 comments on commit 9ab0956

Please sign in to comment.