mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-14 01:37:07 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
47
lib/providers/items/information_provider.dart
Normal file
47
lib/providers/items/information_provider.dart
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import 'package:chopper/chopper.dart';
|
||||
import 'package:fladder/providers/service_provider.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:fladder/models/information_model.dart';
|
||||
import 'package:fladder/models/item_base_model.dart';
|
||||
import 'package:fladder/providers/api_provider.dart';
|
||||
|
||||
class InformationProviderModel {
|
||||
final InformationModel? model;
|
||||
final bool loading;
|
||||
InformationProviderModel({
|
||||
this.model,
|
||||
this.loading = false,
|
||||
});
|
||||
|
||||
InformationProviderModel copyWith({
|
||||
InformationModel? model,
|
||||
bool? loading,
|
||||
}) {
|
||||
return InformationProviderModel(
|
||||
model: model ?? this.model,
|
||||
loading: loading ?? this.loading,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final informationProvider =
|
||||
StateNotifierProvider.autoDispose.family<InformationNotifier, InformationProviderModel, String>((ref, id) {
|
||||
return InformationNotifier(ref);
|
||||
});
|
||||
|
||||
class InformationNotifier extends StateNotifier<InformationProviderModel> {
|
||||
InformationNotifier(this.ref) : super(InformationProviderModel());
|
||||
|
||||
final Ref ref;
|
||||
|
||||
late final JellyService api = ref.read(jellyApiProvider);
|
||||
|
||||
Future<Response> getItemInformation(ItemBaseModel item) async {
|
||||
state = state.copyWith(loading: true);
|
||||
final response = await api.usersUserIdItemsItemIdGetBaseItem(itemId: item.id);
|
||||
await Future.delayed(const Duration(milliseconds: 250));
|
||||
state = state.copyWith(loading: false, model: InformationModel.fromResponse(response.body));
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue