need help.
import 'package:atf/global/helpers.dart';
import 'package:atf/models/phrase/phrase_model.dart';
import 'package:atf/network/api_service.dart';
import 'package:atf/network/api_urls.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'phrase_state.freezed.dart';
@freezed
class PhraseState with _$PhraseState {
const factory PhraseState({
@Default(false) bool isLoading,
required PhraseModel phraseModel,
}) = _PhraseState;
const PhraseState._();
}
class PhraseNotifier extends StateNotifier<PhraseState> {
PhraseNotifier() : super(const PhraseState(phraseModel: PhraseModel())) {
loadPhrase();
}
loadPhrase() async {
state = state.copyWith(isLoading: true);
final response = await ApiService().generalGet(endPoint: ApiUrls.generatePhrase);
final getPhrase = phraseModelFromJson(response?.data);
logger.d(getPhrase.phrases);
state = state.copyWith(isLoading: false, phraseModel: getPhrase);
}
}
final getPhraseProvider = StateNotifierProvider<PhraseNotifier, PhraseState>((ref) {
return PhraseNotifier();
});
How can I convert this with @riverpod annotation? pardon my mistake.
you need help ?
Yes I do
Обсуждают сегодня