📱 Fix attachment list responsive issue

This commit is contained in:
LittleSheep 2024-12-02 22:42:31 +08:00
parent 7a617a4f8c
commit a70092c6f4
6 changed files with 135 additions and 107 deletions

View File

@ -79,7 +79,7 @@ final _appRoutes = [
), ),
), ),
GoRoute( GoRoute(
path: '/pub/:name', path: '/publishers/:name',
name: 'postPublisher', name: 'postPublisher',
builder: (context, state) => AppBackground( builder: (context, state) => AppBackground(
child: PostPublisherScreen(name: state.pathParameters['name']!), child: PostPublisherScreen(name: state.pathParameters['name']!),

View File

@ -157,7 +157,14 @@ class _UnauthorizedAccountScreen extends StatelessWidget {
leading: const Icon(Symbols.login), leading: const Icon(Symbols.login),
trailing: const Icon(Symbols.chevron_right), trailing: const Icon(Symbols.chevron_right),
onTap: () { onTap: () {
GoRouter.of(context).pushNamed('authLogin'); GoRouter.of(context).pushNamed('authLogin').then((value) {
if (value == true && context.mounted) {
final ua = context.read<UserProvider>();
context.showSnackbar('loginSuccess'.tr(args: [
'@${ua.user?.name} (${ua.user?.nick})',
]));
}
});
}, },
), ),
ListTile( ListTile(

View File

@ -154,13 +154,9 @@ class _LoginCheckScreenState extends State<_LoginCheckScreen> {
sn.setTokenPair(atk, rtk); sn.setTokenPair(atk, rtk);
if (!mounted) return; if (!mounted) return;
final user = context.read<UserProvider>(); final user = context.read<UserProvider>();
final userinfo = await user.refreshUser(); await user.refreshUser();
context.showSnackbar('loginSuccess'.tr(args: [ if (!mounted) return;
'@${userinfo!.name} (${userinfo.nick})', Navigator.pop(context, true);
]));
await Future.delayed(const Duration(milliseconds: 1850), () {
Navigator.pop(context);
});
} catch (err) { } catch (err) {
context.showErrorDialog(err); context.showErrorDialog(err);
return; return;

View File

@ -142,7 +142,7 @@ class _AttachmentZoomViewState extends State<AttachmentZoomView> {
Positioned( Positioned(
left: 16, left: 16,
right: 16, right: 16,
bottom: 16, bottom: 16 + MediaQuery.of(context).padding.bottom,
child: Material( child: Material(
color: Colors.transparent, color: Colors.transparent,
child: Builder(builder: (context) { child: Builder(builder: (context) {

View File

@ -1,3 +1,5 @@
import 'dart:math' as math;
import 'package:dismissible_page/dismissible_page.dart'; import 'package:dismissible_page/dismissible_page.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -36,10 +38,10 @@ class _AttachmentListState extends State<AttachmentList> {
(_) => const Uuid().v4(), (_) => const Uuid().v4(),
); );
static const double kAttachmentMaxWidth = 640;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final aspectRatio = widget.data[0]?.metadata['ratio']?.toDouble() ?? 1;
return LayoutBuilder( return LayoutBuilder(
builder: (context, layoutConstraints) { builder: (context, layoutConstraints) {
final borderSide = widget.bordered final borderSide = widget.bordered
@ -48,98 +50,40 @@ class _AttachmentListState extends State<AttachmentList> {
final backgroundColor = Theme.of(context).colorScheme.surfaceContainer; final backgroundColor = Theme.of(context).colorScheme.surfaceContainer;
final constraints = BoxConstraints( final constraints = BoxConstraints(
minWidth: 80, minWidth: 80,
maxWidth: layoutConstraints.maxWidth - 20,
maxHeight: widget.maxHeight ?? double.infinity, maxHeight: widget.maxHeight ?? double.infinity,
maxWidth: layoutConstraints.maxWidth - 20,
); );
if (widget.data.isEmpty) return const SizedBox.shrink(); if (widget.data.isEmpty) return const SizedBox.shrink();
if (widget.data.length == 1) { if (widget.data.length == 1) {
return AspectRatio( final singleAspectRatio =
aspectRatio: widget.data[0]?.metadata['ratio']?.toDouble() ?? widget.data[0]?.metadata['ratio']?.toDouble() ??
switch (widget.data[0]?.mimetype.split('/').firstOrNull) { switch (widget.data[0]?.mimetype.split('/').firstOrNull) {
'audio' => 16 / 9, 'audio' => 16 / 9,
'video' => 16 / 9, 'video' => 16 / 9,
_ => 1, _ => 1,
}, };
child: GestureDetector(
child: Builder(
builder: (context) {
if (ResponsiveBreakpoints.of(context).largerThan(MOBILE) ||
widget.noGrow) {
return Padding(
// Single child list-like displaying
padding: widget.listPadding ?? EdgeInsets.zero,
child: Container(
constraints: constraints,
decoration: BoxDecoration(
color: backgroundColor,
border: Border(top: borderSide, bottom: borderSide),
borderRadius: AttachmentList.kDefaultRadius,
),
child: ClipRRect(
borderRadius: AttachmentList.kDefaultRadius,
child: AttachmentItem(
data: widget.data[0],
heroTag: heroTags[0],
),
),
),
);
}
return Container( return Container(
decoration: BoxDecoration( constraints: ResponsiveBreakpoints.of(context).largerThan(MOBILE)
color: backgroundColor, ? constraints.copyWith(
border: Border(top: borderSide, bottom: borderSide), maxWidth: math.min(
constraints.maxWidth,
kAttachmentMaxWidth,
), ),
child: AttachmentItem( )
data: widget.data[0], : null,
heroTag: heroTags.first, child: AspectRatio(
), aspectRatio: singleAspectRatio,
); child: GestureDetector(
}, child: Builder(
), builder: (context) {
onTap: () { if (ResponsiveBreakpoints.of(context).largerThan(MOBILE) ||
context.pushTransparentRoute( widget.noGrow) {
AttachmentZoomView( return Padding(
data: widget.data.where((ele) => ele != null).cast(), // Single child list-like displaying
initialIndex: 0, padding: widget.listPadding ?? EdgeInsets.zero,
heroTags: heroTags, child: Container(
),
backgroundColor: Colors.black.withOpacity(0.7),
rootNavigator: true,
);
},
),
);
}
return AspectRatio(
aspectRatio: aspectRatio,
child: Container(
constraints: BoxConstraints(maxHeight: widget.maxHeight ?? 320),
child: ScrollConfiguration(
behavior: _AttachmentListScrollBehavior(),
child: ListView.separated(
shrinkWrap: true,
itemCount: widget.data.length,
itemBuilder: (context, idx) {
return GestureDetector(
onTap: () {
context.pushTransparentRoute(
AttachmentZoomView(
data: widget.data.where((ele) => ele != null).cast(),
initialIndex: idx,
heroTags: heroTags,
),
backgroundColor: Colors.black.withOpacity(0.7),
rootNavigator: true,
);
},
child: Stack(
children: [
Container(
constraints: constraints,
decoration: BoxDecoration( decoration: BoxDecoration(
color: backgroundColor, color: backgroundColor,
border: Border(top: borderSide, bottom: borderSide), border: Border(top: borderSide, bottom: borderSide),
@ -148,19 +92,100 @@ class _AttachmentListState extends State<AttachmentList> {
child: ClipRRect( child: ClipRRect(
borderRadius: AttachmentList.kDefaultRadius, borderRadius: AttachmentList.kDefaultRadius,
child: AttachmentItem( child: AttachmentItem(
data: widget.data[idx], data: widget.data[0],
heroTag: heroTags[idx], heroTag: heroTags[0],
), ),
), ),
), ),
Positioned( );
right: 8, }
bottom: 12,
child: Chip( return Container(
label: Text('${idx + 1}/${widget.data.length}'), decoration: BoxDecoration(
), color: backgroundColor,
border: Border(top: borderSide, bottom: borderSide),
),
child: AttachmentItem(
data: widget.data[0],
heroTag: heroTags.first,
),
);
},
),
onTap: () {
context.pushTransparentRoute(
AttachmentZoomView(
data: widget.data.where((ele) => ele != null).cast(),
initialIndex: 0,
heroTags: heroTags,
),
backgroundColor: Colors.black.withOpacity(0.7),
rootNavigator: true,
);
},
),
),
);
}
return AspectRatio(
aspectRatio: widget.data.firstOrNull?.metadata['ratio'] ?? 1,
child: Container(
constraints: BoxConstraints(maxHeight: constraints.maxHeight),
child: ScrollConfiguration(
behavior: _AttachmentListScrollBehavior(),
child: ListView.separated(
shrinkWrap: true,
itemCount: widget.data.length,
itemBuilder: (context, idx) {
return Container(
constraints: constraints,
child: AspectRatio(
aspectRatio: widget.data[idx]?.metadata['ratio'] ?? 1,
child: GestureDetector(
onTap: () {
context.pushTransparentRoute(
AttachmentZoomView(
data: widget.data
.where((ele) => ele != null)
.cast(),
initialIndex: idx,
heroTags: heroTags,
),
backgroundColor: Colors.black.withOpacity(0.7),
rootNavigator: true,
);
},
child: Stack(
fit: StackFit.expand,
children: [
Container(
decoration: BoxDecoration(
color: backgroundColor,
border: Border(
top: borderSide,
bottom: borderSide,
),
borderRadius: AttachmentList.kDefaultRadius,
),
child: ClipRRect(
borderRadius: AttachmentList.kDefaultRadius,
child: AttachmentItem(
data: widget.data[idx],
heroTag: heroTags[idx],
),
),
),
Positioned(
right: 8,
bottom: 8,
child: Chip(
label: Text('${idx + 1}/${widget.data.length}'),
),
),
],
), ),
], ),
), ),
); );
}, },

View File

@ -83,7 +83,7 @@ class PostItem extends StatelessWidget {
AttachmentList( AttachmentList(
data: data.preload!.attachments!, data: data.preload!.attachments!,
bordered: true, bordered: true,
maxHeight: 480, maxHeight: 560,
listPadding: const EdgeInsets.symmetric(horizontal: 12), listPadding: const EdgeInsets.symmetric(horizontal: 12),
), ),
Container( Container(