🎨 Formatted all the code
This commit is contained in:
@ -49,7 +49,8 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> pickImageToUpload(BuildContext context, ImageSource source) async {
|
||||
Future<void> pickImageToUpload(
|
||||
BuildContext context, ImageSource source) async {
|
||||
final auth = context.read<AuthProvider>();
|
||||
if (!await auth.isAuthorized()) return;
|
||||
|
||||
@ -74,7 +75,8 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> pickVideoToUpload(BuildContext context, ImageSource source) async {
|
||||
Future<void> pickVideoToUpload(
|
||||
BuildContext context, ImageSource source) async {
|
||||
final auth = context.read<AuthProvider>();
|
||||
if (!await auth.isAuthorized()) return;
|
||||
|
||||
@ -102,7 +104,8 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
Future<void> uploadAttachment(File file, String hashcode) async {
|
||||
final auth = context.read<AuthProvider>();
|
||||
|
||||
final req = MultipartRequest('POST', getRequestUri(widget.provider, '/api/attachments'));
|
||||
final req = MultipartRequest(
|
||||
'POST', getRequestUri(widget.provider, '/api/attachments'));
|
||||
req.files.add(await MultipartFile.fromPath('attachment', file.path));
|
||||
req.fields['hashcode'] = hashcode;
|
||||
|
||||
@ -118,10 +121,12 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> disposeAttachment(BuildContext context, Attachment item, int index) async {
|
||||
Future<void> disposeAttachment(
|
||||
BuildContext context, Attachment item, int index) async {
|
||||
final auth = context.read<AuthProvider>();
|
||||
|
||||
final req = MultipartRequest('DELETE', getRequestUri(widget.provider, '/api/attachments/${item.id}'));
|
||||
final req = MultipartRequest('DELETE',
|
||||
getRequestUri(widget.provider, '/api/attachments/${item.id}'));
|
||||
|
||||
setState(() => _isSubmitting = true);
|
||||
var res = await auth.client!.send(req);
|
||||
@ -162,7 +167,17 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
if (bytes == 0) return '0 Bytes';
|
||||
const k = 1024;
|
||||
final dm = decimals < 0 ? 0 : decimals;
|
||||
final sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
||||
final sizes = [
|
||||
'Bytes',
|
||||
'KiB',
|
||||
'MiB',
|
||||
'GiB',
|
||||
'TiB',
|
||||
'PiB',
|
||||
'EiB',
|
||||
'ZiB',
|
||||
'YiB'
|
||||
];
|
||||
final i = (math.log(bytes) / math.log(k)).floor().toInt();
|
||||
return '${(bytes / math.pow(k, i)).toStringAsFixed(dm)} ${sizes[i]}';
|
||||
}
|
||||
@ -180,7 +195,8 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, top: 20, bottom: 12),
|
||||
padding:
|
||||
const EdgeInsets.only(left: 8, right: 8, top: 20, bottom: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@ -199,7 +215,9 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData && snapshot.data == true) {
|
||||
return TextButton(
|
||||
onPressed: _isSubmitting ? null : () => viewAttachMethods(context),
|
||||
onPressed: _isSubmitting
|
||||
? null
|
||||
: () => viewAttachMethods(context),
|
||||
style: TextButton.styleFrom(shape: const CircleBorder()),
|
||||
child: const Icon(Icons.add_circle),
|
||||
);
|
||||
@ -211,7 +229,9 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
],
|
||||
),
|
||||
),
|
||||
_isSubmitting ? const LinearProgressIndicator().animate().scaleX() : Container(),
|
||||
_isSubmitting
|
||||
? const LinearProgressIndicator().animate().scaleX()
|
||||
: Container(),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: _attachments.length,
|
||||
@ -243,7 +263,8 @@ class _AttachmentEditorState extends State<AttachmentEditor> {
|
||||
foregroundColor: Colors.red,
|
||||
),
|
||||
child: const Icon(Icons.delete),
|
||||
onPressed: () => disposeAttachment(context, element, index),
|
||||
onPressed: () =>
|
||||
disposeAttachment(context, element, index),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -303,7 +324,8 @@ class AttachmentEditorMethodPopup extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.add_photo_alternate, color: Colors.indigo),
|
||||
const Icon(Icons.add_photo_alternate,
|
||||
color: Colors.indigo),
|
||||
const SizedBox(height: 8),
|
||||
Text(AppLocalizations.of(context)!.pickPhoto),
|
||||
],
|
||||
|
@ -36,6 +36,17 @@ class _AttachmentItemState extends State<AttachmentItem> {
|
||||
);
|
||||
late final _videoController = VideoController(_videoPlayer);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.type != 1) {
|
||||
_videoPlayer.open(
|
||||
Media(widget.url),
|
||||
play: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const borderRadius = Radius.circular(8);
|
||||
@ -53,6 +64,7 @@ class _AttachmentItemState extends State<AttachmentItem> {
|
||||
children: [
|
||||
Image.network(
|
||||
widget.url,
|
||||
key: Key(getTag()),
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
fit: BoxFit.cover,
|
||||
@ -63,6 +75,7 @@ class _AttachmentItemState extends State<AttachmentItem> {
|
||||
right: 12,
|
||||
bottom: 8,
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Chip(label: Text(widget.badge!)),
|
||||
),
|
||||
)
|
||||
@ -83,11 +96,6 @@ class _AttachmentItemState extends State<AttachmentItem> {
|
||||
},
|
||||
);
|
||||
} else {
|
||||
_videoPlayer.open(
|
||||
Media(widget.url),
|
||||
play: false,
|
||||
);
|
||||
|
||||
content = ClipRRect(
|
||||
borderRadius: const BorderRadius.all(borderRadius),
|
||||
child: Video(
|
||||
@ -121,9 +129,11 @@ class AttachmentList extends StatelessWidget {
|
||||
final List<Attachment> items;
|
||||
final String provider;
|
||||
|
||||
const AttachmentList({super.key, required this.items, required this.provider});
|
||||
const AttachmentList(
|
||||
{super.key, required this.items, required this.provider});
|
||||
|
||||
Uri getFileUri(String fileId) => getRequestUri(provider, '/api/attachments/o/$fileId');
|
||||
Uri getFileUri(String fileId) =>
|
||||
getRequestUri(provider, '/api/attachments/o/$fileId');
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -47,7 +47,8 @@ class _PostItemState extends State<PostItem> {
|
||||
}
|
||||
|
||||
void viewComments() {
|
||||
final PagingController<int, Post> commentPaging = PagingController(firstPageKey: 0);
|
||||
final PagingController<int, Post> commentPaging =
|
||||
PagingController(firstPageKey: 0);
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
@ -87,10 +88,12 @@ class _PostItemState extends State<PostItem> {
|
||||
Widget renderAttachments() {
|
||||
if (widget.item.modelType == 'article') return Container();
|
||||
|
||||
if (widget.item.attachments != null && widget.item.attachments!.isNotEmpty) {
|
||||
if (widget.item.attachments != null &&
|
||||
widget.item.attachments!.isNotEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: AttachmentList(items: widget.item.attachments!, provider: 'interactive'),
|
||||
child: AttachmentList(
|
||||
items: widget.item.attachments!, provider: 'interactive'),
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
@ -130,8 +133,9 @@ class _PostItemState extends State<PostItem> {
|
||||
);
|
||||
}
|
||||
|
||||
String getAuthorDescribe() =>
|
||||
widget.item.author.description.isNotEmpty ? widget.item.author.description : 'No description yet.';
|
||||
String getAuthorDescribe() => widget.item.author.description.isNotEmpty
|
||||
? widget.item.author.description
|
||||
: 'No description yet.';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -177,7 +181,8 @@ class _PostItemState extends State<PostItem> {
|
||||
children: [
|
||||
...headingParts,
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 12, right: 12, top: 4),
|
||||
padding:
|
||||
const EdgeInsets.only(left: 12, right: 12, top: 4),
|
||||
child: renderContent(),
|
||||
),
|
||||
renderAttachments(),
|
||||
|
@ -106,7 +106,8 @@ class _ReactionActionPopupState extends State<ReactionActionPopup> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.only(left: 8, right: 8, top: 20, bottom: 12),
|
||||
padding:
|
||||
const EdgeInsets.only(left: 8, right: 8, top: 20, bottom: 12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
@ -118,7 +119,9 @@ class _ReactionActionPopupState extends State<ReactionActionPopup> {
|
||||
),
|
||||
),
|
||||
),
|
||||
_isSubmitting ? const LinearProgressIndicator().animate().scaleX() : Container(),
|
||||
_isSubmitting
|
||||
? const LinearProgressIndicator().animate().scaleX()
|
||||
: Container(),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: reactions.length,
|
||||
|
Reference in New Issue
Block a user