Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 79 additions & 6 deletions lib/view/widget/note_footer.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:misskey_dart/misskey_dart.dart' hide Clip;

import '../../constant/colors.dart';
import '../../extension/note_extension.dart';
import '../../extension/text_style_extension.dart';
import '../../i18n/strings.g.dart';
import '../../model/account.dart';
import '../../provider/account_settings_notifier_provider.dart';
import '../../provider/api/i_notifier_provider.dart';
import '../../provider/api/meta_notifier_provider.dart';
import '../../provider/api/misskey_provider.dart';
import '../../provider/appear_note_provider.dart';
import '../../provider/general_settings_notifier_provider.dart';
import '../../provider/note_provider.dart';
Expand All @@ -29,7 +32,7 @@ import 'renote_sheet.dart';
import 'renote_users_sheet.dart';
import 'translated_note_sheet.dart';

class NoteFooter extends ConsumerWidget {
class NoteFooter extends HookConsumerWidget {
const NoteFooter({
super.key,
required this.account,
Expand Down Expand Up @@ -88,6 +91,7 @@ class NoteFooter extends ConsumerWidget {
NoteVisibility.followers => isMyNote,
_ => false,
};
final renotedBy = useState(note.isRenote ? noteId : null);

return LayoutBuilder(
builder: (context, constraints) {
Expand Down Expand Up @@ -164,17 +168,74 @@ class NoteFooter extends ConsumerWidget {
? t.misskey.renote
: null,
onPressed: !account.isGuest
? () {
? () async {
if (appearNote.id.isEmpty) return;
if (renotedBy.value case final noteId?) {
final unrenote =
await showModalBottomSheet<bool>(
context: context,
builder: (context) => ListView(
shrinkWrap: true,
children: [
ListTile(
leading:
const Icon(Icons.repeat_rounded),
title: Text(t.misskey.renote),
onTap: () => context.pop(false),
),
ListTile(
leading: const Icon(Icons.delete),
title: Text(t.misskey.unrenote),
onTap: () => context.pop(true),
iconColor: Theme.of(context)
.colorScheme
.error,
textColor: Theme.of(context)
.colorScheme
.error,
),
],
),
);
if (!context.mounted) return;
if (unrenote == null) return;
if (unrenote) {
final result = await futureWithDialog(
context,
ref
.read(misskeyProvider(account))
.notes
.delete(
NotesDeleteRequest(noteId: noteId),
)
.then((_) => true),
);
if (!context.mounted) return;
if (result != null) {
ref
.read(
notesNotifierProvider(account)
.notifier,
)
.remove(noteId);
renotedBy.value = null;
}
return;
}
}
if (showQuoteButton) {
showModalBottomSheet<void>(
final result =
await showModalBottomSheet<Note>(
context: context,
builder: (context) => RenoteSheet(
account: account,
note: appearNote,
),
clipBehavior: Clip.hardEdge,
);
if (result != null) {
renotedBy.value = result.id;
}
} else {
ref
.read(
Expand All @@ -184,23 +245,35 @@ class NoteFooter extends ConsumerWidget {
if (focusPostForm case final focusPostForm?) {
focusPostForm();
} else {
context.push('/$account/post');
await context.push('/$account/post');
}
}
}
: null,
icon: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.repeat_rounded),
Icon(
Icons.repeat_rounded,
color: renotedBy.value != null
? Theme.of(context).colorScheme.primary
: null,
),
if (appearNote.renoteCount > 0)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 2.0,
),
child: Text(
NumberFormat().format(appearNote.renoteCount),
style: style,
style: style.apply(
color: renotedBy.value != null
? Theme.of(context)
.colorScheme
.primary
.withOpacity(0.6)
: null,
),
),
),
],
Expand Down
4 changes: 2 additions & 2 deletions lib/view/widget/renote_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class RenoteSheet extends HookConsumerWidget {
.read(notesNotifierProvider(account).notifier)
.add(result);
if (!context.mounted) return;
context.pop();
context.pop(result);
}
}
} else {
Expand All @@ -239,7 +239,7 @@ class RenoteSheet extends HookConsumerWidget {
ref
.read(notesNotifierProvider(account).notifier)
.add(result);
context.pop();
context.pop(result);
}
}
}
Expand Down
Loading