mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 02:39:19 +08:00
feat: reorganize attachments provider and model structure
This commit is contained in:
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../features/chat/models/chat_models.dart';
|
||||
import '../../../features/chat/viewmodel/chat_viewmodel.dart';
|
||||
import '../../../features/chat/providers/attachments_provider.dart';
|
||||
import '../../providers/attachments_provider.dart';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import '../../services/openapi_import_service.dart';
|
||||
import '../../../features/chat/view/widgets/openapi_operation_picker_dialog.dart';
|
||||
|
||||
19
lib/dashbot/core/model/chat_attachment.dart
Normal file
19
lib/dashbot/core/model/chat_attachment.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class ChatAttachment {
|
||||
final String id;
|
||||
final String name;
|
||||
final String mimeType;
|
||||
final int sizeBytes;
|
||||
final Uint8List data;
|
||||
final DateTime createdAt;
|
||||
|
||||
ChatAttachment({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.mimeType,
|
||||
required this.sizeBytes,
|
||||
required this.data,
|
||||
required this.createdAt,
|
||||
});
|
||||
}
|
||||
40
lib/dashbot/core/providers/attachments_provider.dart
Normal file
40
lib/dashbot/core/providers/attachments_provider.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
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();
|
||||
});
|
||||
Reference in New Issue
Block a user