Implements SMS reading functionality to automatically track expenses. - Adds necessary permissions for reading SMS messages in AndroidManifest.xml. - Registers SmsService and SmsCubit in the dependency injection container. - Adds a new SMS page to the bottom navigation bar. - Introduces new localization strings for the SMS page title and permission denied message. - Sets minSdk to 23.
34 lines
1.3 KiB
Dart
34 lines
1.3 KiB
Dart
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:budget_app/logic/sms/sms_state.dart';
|
|
import 'package:budget_app/services/sms_service.dart';
|
|
|
|
/// Cubit для управления состоянием SMS.
|
|
///
|
|
/// Отвечает за загрузку SMS сообщений и обработку разрешений.
|
|
class SmsCubit extends Cubit<SmsState> {
|
|
final SmsService _smsService;
|
|
|
|
SmsCubit(this._smsService) : super(SmsInitial());
|
|
|
|
/// Загружает последние 10 SMS сообщений.
|
|
///
|
|
/// Перед загрузкой запрашивает необходимые разрешения.
|
|
/// В случае успеха, переходит в состояние [SmsLoaded].
|
|
/// В случае отказа в разрешениях, переходит в состояние [SmsPermissionDenied].
|
|
/// В случае ошибки, переходит в состояние [SmsError].
|
|
Future<void> loadLastMessages() async {
|
|
emit(SmsLoading());
|
|
try {
|
|
final hasPermissions = await _smsService.requestPermissions();
|
|
if (hasPermissions) {
|
|
final messages = await _smsService.getLastSmsMessages(10);
|
|
emit(SmsLoaded(messages));
|
|
} else {
|
|
emit(SmsPermissionDenied());
|
|
}
|
|
} catch (e) {
|
|
emit(SmsError(e.toString()));
|
|
}
|
|
}
|
|
}
|