Merge branch 'attachment-viewing-updates' of gitlab.com:mysocialportal/relatica into attachment-viewing-updates

This commit is contained in:
Hank Grabowski 2023-04-24 08:21:12 -04:00
commit e24aceaeeb
2 changed files with 42 additions and 23 deletions

View file

@ -29,7 +29,7 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
MediaKit.ensureInitialized();
// await dotenv.load(fileName: '.env');
const enablePreview = true;
const enablePreview = false;
Logger.root.level = Level.FINER;
Logger.root.onRecord.listen((event) {
final logName = event.loggerName.isEmpty ? 'ROOT' : event.loggerName;

View file

@ -37,6 +37,25 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
currentIndex = widget.initialIndex;
}
void nextAttachment() {
if (currentIndex >= widget.attachments.length - 1) {
return;
}
setState(() {
currentIndex++;
});
}
void previousAttachment() {
if (currentIndex < 1) {
return;
}
setState(() {
currentIndex--;
});
}
Future<void> saveImage(
BuildContext context,
MediaAttachment attachment,
@ -74,7 +93,11 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
@override
Widget build(BuildContext context) {
final currentAttachment = widget.attachments[currentIndex];
final height = MediaQuery.of(context).size.height;
final width = MediaQuery.of(context).size.width;
final height = MediaQuery.of(context).size.height * 0.9;
final descriptionHeightPct = widget.attachments.isEmpty ? 0.0 : 0.1;
final mediaHeight = height * (1 - descriptionHeightPct);
final descriptionHeight = height * descriptionHeightPct;
return Scaffold(
appBar: AppBar(
actions: [
@ -89,22 +112,23 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
SizedBox(
width: width,
height: mediaHeight,
child: InteractiveViewer(
maxScale: 10.0,
scaleFactor: 400,
child: LoginAwareCachedNetworkImage(
imageUrl:
widget.attachments[currentIndex].uri.toString()),
imageUrl: currentAttachment.uri.toString()),
),
),
if (currentAttachment.description.isNotEmpty)
buildTextArea(currentAttachment),
buildTextArea(currentAttachment, descriptionHeight),
],
),
if (widget.attachments.length > 1) ...[
Positioned(
bottom: height * 0.5,
bottom: mediaHeight * 0.5,
child: Opacity(
opacity: 0.8,
child: currentIndex < 1
@ -113,18 +137,14 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
color: Colors.black,
child: IconButton(
color: Colors.white,
onPressed: () {
setState(() {
currentIndex--;
});
},
onPressed: previousAttachment,
icon: const Icon(Icons.chevron_left),
),
),
),
),
Positioned(
bottom: height * 0.5,
bottom: mediaHeight * 0.5,
right: 0.0,
child: Opacity(
opacity: 0.8,
@ -134,11 +154,7 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
color: Colors.black,
child: IconButton(
color: Colors.white,
onPressed: () {
setState(() {
currentIndex++;
});
},
onPressed: nextAttachment,
icon: const Icon(Icons.chevron_right),
),
),
@ -151,10 +167,9 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
);
}
Widget buildTextArea(MediaAttachment attachment) {
final height = MediaQuery.of(context).size.height * 0.1;
Widget buildTextArea(MediaAttachment attachment, double height) {
return Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: SizedBox(
height: height,
child: attachment.description.isEmpty
@ -163,8 +178,12 @@ class _MediaViewerScreenState extends State<MediaViewerScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: SingleChildScrollView(
child: Text(attachment.description),
child: Scrollbar(
controller: ScrollController(),
thumbVisibility: true,
child: SingleChildScrollView(
child: Text(attachment.description),
),
)),
IconButton(
onPressed: () async {