|
|
@ -3,13 +3,20 @@ import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
|
|
|
|
import 'package:fluffychat/utils/url_launcher.dart';
|
|
|
|
|
|
|
|
import 'package:fluffychat/widgets/mxc_image.dart';
|
|
|
|
import '../../widgets/avatar.dart';
|
|
|
|
import '../../widgets/avatar.dart';
|
|
|
|
import 'events/image_bubble.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StickerPickerDialog extends StatefulWidget {
|
|
|
|
class StickerPickerDialog extends StatefulWidget {
|
|
|
|
final Room room;
|
|
|
|
final Room room;
|
|
|
|
|
|
|
|
final void Function(ImagePackImageContent) onSelected;
|
|
|
|
|
|
|
|
|
|
|
|
const StickerPickerDialog({required this.room, super.key});
|
|
|
|
const StickerPickerDialog({
|
|
|
|
|
|
|
|
required this.onSelected,
|
|
|
|
|
|
|
|
required this.room,
|
|
|
|
|
|
|
|
super.key,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
StickerPickerDialogState createState() => StickerPickerDialogState();
|
|
|
|
StickerPickerDialogState createState() => StickerPickerDialogState();
|
|
|
@ -58,24 +65,14 @@ class StickerPickerDialogState extends State<StickerPickerDialog> {
|
|
|
|
GridView.builder(
|
|
|
|
GridView.builder(
|
|
|
|
itemCount: imageKeys.length,
|
|
|
|
itemCount: imageKeys.length,
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
|
|
|
maxCrossAxisExtent: 100,
|
|
|
|
maxCrossAxisExtent: 128,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
shrinkWrap: true,
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
itemBuilder: (BuildContext context, int imageIndex) {
|
|
|
|
itemBuilder: (BuildContext context, int imageIndex) {
|
|
|
|
final image = pack.images[imageKeys[imageIndex]]!;
|
|
|
|
final image = pack.images[imageKeys[imageIndex]]!;
|
|
|
|
final fakeEvent = Event(
|
|
|
|
|
|
|
|
type: EventTypes.Sticker,
|
|
|
|
|
|
|
|
content: {
|
|
|
|
|
|
|
|
'url': image.url.toString(),
|
|
|
|
|
|
|
|
'info': image.info,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
originServerTs: DateTime.now(),
|
|
|
|
|
|
|
|
room: widget.room,
|
|
|
|
|
|
|
|
eventId: 'fake_event',
|
|
|
|
|
|
|
|
senderId: widget.room.client.userID!,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
return InkWell(
|
|
|
|
return InkWell(
|
|
|
|
|
|
|
|
radius: AppConfig.borderRadius,
|
|
|
|
key: ValueKey(image.url.toString()),
|
|
|
|
key: ValueKey(image.url.toString()),
|
|
|
|
onTap: () {
|
|
|
|
onTap: () {
|
|
|
|
// copy the image
|
|
|
|
// copy the image
|
|
|
@ -83,17 +80,16 @@ class StickerPickerDialogState extends State<StickerPickerDialog> {
|
|
|
|
ImagePackImageContent.fromJson(image.toJson().copy());
|
|
|
|
ImagePackImageContent.fromJson(image.toJson().copy());
|
|
|
|
// set the body, if it doesn't exist, to the key
|
|
|
|
// set the body, if it doesn't exist, to the key
|
|
|
|
imageCopy.body ??= imageKeys[imageIndex];
|
|
|
|
imageCopy.body ??= imageKeys[imageIndex];
|
|
|
|
Navigator.of(context, rootNavigator: false)
|
|
|
|
widget.onSelected(imageCopy);
|
|
|
|
.pop<ImagePackImageContent>(imageCopy);
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
child: AbsorbPointer(
|
|
|
|
child: AbsorbPointer(
|
|
|
|
absorbing: true,
|
|
|
|
absorbing: true,
|
|
|
|
child: ImageBubble(
|
|
|
|
child: MxcImage(
|
|
|
|
fakeEvent,
|
|
|
|
uri: image.url,
|
|
|
|
tapToView: false,
|
|
|
|
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
width: 100,
|
|
|
|
width: 128,
|
|
|
|
height: 100,
|
|
|
|
height: 128,
|
|
|
|
|
|
|
|
animated: true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -112,28 +108,47 @@ class StickerPickerDialogState extends State<StickerPickerDialog> {
|
|
|
|
floating: true,
|
|
|
|
floating: true,
|
|
|
|
pinned: true,
|
|
|
|
pinned: true,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
titleSpacing: 0,
|
|
|
|
|
|
|
|
backgroundColor: Theme.of(context).dialogBackgroundColor,
|
|
|
|
backgroundColor: Theme.of(context).dialogBackgroundColor,
|
|
|
|
leading: IconButton(
|
|
|
|
title: SizedBox(
|
|
|
|
icon: const Icon(Icons.close),
|
|
|
|
height: 42,
|
|
|
|
onPressed: Navigator.of(context, rootNavigator: false).pop,
|
|
|
|
child: TextField(
|
|
|
|
),
|
|
|
|
autofocus: false,
|
|
|
|
title: TextField(
|
|
|
|
decoration: InputDecoration(
|
|
|
|
autofocus: false,
|
|
|
|
hintText: L10n.of(context)!.search,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.search_outlined),
|
|
|
|
hintText: L10n.of(context)!.search,
|
|
|
|
contentPadding: EdgeInsets.zero,
|
|
|
|
suffix: const Icon(Icons.search_outlined),
|
|
|
|
),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
onChanged: (s) => setState(() => searchFilter = s),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onChanged: (s) => setState(() => searchFilter = s),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverList(
|
|
|
|
if (packSlugs.isEmpty)
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
SliverFillRemaining(
|
|
|
|
packBuilder,
|
|
|
|
child: Center(
|
|
|
|
childCount: packSlugs.length,
|
|
|
|
child: Column(
|
|
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Text(L10n.of(context)!.noEmotesFound),
|
|
|
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
|
|
|
OutlinedButton.icon(
|
|
|
|
|
|
|
|
onPressed: () => UrlLauncher(
|
|
|
|
|
|
|
|
context,
|
|
|
|
|
|
|
|
'https://matrix.to/#/#fluffychat-stickers:janian.de',
|
|
|
|
|
|
|
|
).launchUrl(),
|
|
|
|
|
|
|
|
icon: const Icon(Icons.explore_outlined),
|
|
|
|
|
|
|
|
label: Text(L10n.of(context)!.discover),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
SliverList(
|
|
|
|
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
|
|
|
|
packBuilder,
|
|
|
|
|
|
|
|
childCount: packSlugs.length,
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|