Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Feb 25, 2025
1 parent 08e3ef1 commit 9ab3638
Showing 1 changed file with 56 additions and 43 deletions.
99 changes: 56 additions & 43 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1006,68 +1006,81 @@ void _showSavedSnippet({
required ComposeBoxController controller,
}) async {
final store = PerAccountStoreWidget.of(context);
final savedSnippets = store.savedSnippets;
if (savedSnippets == null || savedSnippets.isEmpty) {
showErrorDialog(context: context, title: 'No saved snippets');
return;
}
unawaited(showModalBottomSheet(
context: context,
// Clip.hardEdge looks bad; Clip.antiAliasWithSaveLayer looks pixel-perfect
// on my iPhone 13 Pro but is marked as "much slower":
// https://api.flutter.dev/flutter/dart-ui/Clip.html
clipBehavior: Clip.antiAlias,
useSafeArea: true,
// Clip.hardEdge looks bad; Clip.antiAliasWithSaveLayer looks pixel-perfect
// on my iPhone 13 Pro but is marked as "much slower":
// https://api.flutter.dev/flutter/dart-ui/Clip.html
clipBehavior: Clip.antiAlias,
useSafeArea: true,
isScrollControlled: true,
builder: (BuildContext context) {
return PerAccountStoreWidget(
accountId: store.accountId,
child: _SavedSnippetPicker(context: context, controller: controller));
return _SavedSnippetPicker(
controller: controller,
savedSnippets: savedSnippets);
}));
}

class _SavedSnippetPicker extends StatelessWidget {
const _SavedSnippetPicker({required this.context, required this.controller});
const _SavedSnippetPicker({required this.controller, required this.savedSnippets});

final BuildContext context;
final ComposeBoxController controller;
final List<SavedSnippets> savedSnippets;

void _handleSelect(String content) {
void _handleSelect(BuildContext context, String content) {
if (!content.endsWith('\n')) {
content = '$content\n';
}
controller.content.insertPadded(content);
Navigator.pop(context);
}

Widget buildItem(BuildContext context, int i) {
final designVariables = DesignVariables.of(context);
final savedSnippet = savedSnippets[i];
return Align(
alignment: Alignment.centerLeft,
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
splashFactory: NoSplash.splashFactory),
onPressed: () => _handleSelect(context, savedSnippet.content),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
savedSnippet.title,
style: TextStyle(
fontSize: 14,
height: 16.8 / 14,
color: designVariables.foreground)),
Text(savedSnippet.content,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13,
height: 15.78 / 13,
color: designVariables.foreground.withFadedAlpha(0.5))),
])));
}

@override
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final designVariables = DesignVariables.of(context);
return ListView.builder(
itemCount: store.savedSnippets?.length ?? 0,
itemBuilder: (BuildContext context, int i) {
final savedSnippet = store.savedSnippets![i];
return Align(
alignment: Alignment.centerLeft,
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
splashFactory: NoSplash.splashFactory),
onPressed: () => _handleSelect(savedSnippet.content),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
savedSnippet.title,
style: TextStyle(
fontSize: 14,
height: 16.8 / 14,
color: designVariables.foreground)),
Text(savedSnippet.content,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 13,
height: 15.78 / 13,
color: designVariables.foreground.withFadedAlpha(0.5))),
]),
));
});
return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: savedSnippets.length,
itemBuilder: buildItem)),
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
]));
}
}

Expand Down

0 comments on commit 9ab3638

Please sign in to comment.