mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
41 lines
1.1 KiB
Dart
41 lines
1.1 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:apidash/utils/file_utils.dart';
|
|
|
|
import '../model/chat_attachment.dart';
|
|
|
|
class AttachmentsState {
|
|
final List<ChatAttachment> items;
|
|
const AttachmentsState({this.items = const []});
|
|
|
|
AttachmentsState copyWith({List<ChatAttachment>? items}) =>
|
|
AttachmentsState(items: items ?? this.items);
|
|
}
|
|
|
|
class AttachmentsNotifier extends StateNotifier<AttachmentsState> {
|
|
AttachmentsNotifier() : super(const AttachmentsState());
|
|
|
|
ChatAttachment add({
|
|
required String name,
|
|
required String mimeType,
|
|
required Uint8List data,
|
|
}) {
|
|
final att = ChatAttachment(
|
|
id: getNewUuid(),
|
|
name: name,
|
|
mimeType: mimeType,
|
|
sizeBytes: data.length,
|
|
data: data,
|
|
createdAt: DateTime.now(),
|
|
);
|
|
state = state.copyWith(items: [...state.items, att]);
|
|
debugPrint('[Attachments] Added ${att.name} (${att.sizeBytes} bytes)');
|
|
return att;
|
|
}
|
|
}
|
|
|
|
final attachmentsProvider =
|
|
StateNotifierProvider<AttachmentsNotifier, AttachmentsState>((ref) {
|
|
return AttachmentsNotifier();
|
|
});
|