Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment part 2 #18

Merged
merged 3 commits into from
Jun 13, 2024
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
50 changes: 50 additions & 0 deletions lib/features/core/components/attachment_file_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:popup_menu/popup_menu.dart';

import '../../../nocodb_sdk/models.dart';

class AttachmentFileCard extends HookConsumerWidget {
final NcAttachedFile _file;
final PopupMenu? popupMenu;
const AttachmentFileCard(
this._file, {
this.popupMenu,
super.key,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final anchor = popupMenu != null ? GlobalKey() : null;
final child = Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
const SizedBox(
width: 64,
height: 64,
child: Icon(Icons.description_outlined, size: 48),
),
Container(
padding: const EdgeInsets.all(8),
child: Text(
_file.title,
overflow: TextOverflow.ellipsis,
),
),
],
),
);

return Card(
key: anchor,
elevation: 4,
child: anchor == null
? child
: InkWell(
onTap: () => popupMenu?.show(widgetKey: anchor),
child: child,
),
);
}
}
45 changes: 45 additions & 0 deletions lib/features/core/components/attachment_image_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:popup_menu/popup_menu.dart';

import '../../../nocodb_sdk/client.dart';
import '../../../nocodb_sdk/models.dart';

class AttachmentImageCard extends HookConsumerWidget {
final NcAttachedFile _file;
final PopupMenu? popupMenu;
const AttachmentImageCard(
this._file, {
this.popupMenu,
super.key,
});

@override
Widget build(BuildContext context, WidgetRef ref) {
final anchor = popupMenu != null ? GlobalKey() : null;
final child = SizedBox(
width: 80,
height: 80,
child: CachedNetworkImage(
imageUrl: _file.signedUrl(api.uri),
placeholder: (context, url) => const Padding(
padding: EdgeInsets.all(24),
child: CircularProgressIndicator(),
),
errorWidget: (context, url, error) => const Icon(Icons.error),
),
);

return Card(
key: anchor,
elevation: 4,
child: anchor == null
? child
: InkWell(
onTap: () => popupMenu?.show(widgetKey: anchor),
child: child,
),
);
}
}
9 changes: 9 additions & 0 deletions lib/features/core/components/cell.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../pages/attachment_editor.dart';
import '/nocodb_sdk/symbols.dart';
import '../../../common/flash_wrapper.dart';
import '../../../nocodb_sdk/models.dart';
Expand Down Expand Up @@ -202,6 +203,14 @@ class Cell {
},
);
}
case UITypes.attachment:
return () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AttachmentEditorPage(rowId!, column.title),
),
);
default:
assert(
value is String? ||
Expand Down
1 change: 1 addition & 0 deletions lib/features/core/components/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class Editor extends HookConsumerWidget {
}),
],
child: AttachmentEditor(
rowId: rowId,
column: column,
onUpdate: onUpdate,
),
Expand Down
Loading