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.
55 lines
2.1 KiB
Dart
55 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:budget_app/logic/sms/sms_cubit.dart';
|
|
import 'package:budget_app/logic/sms/sms_state.dart';
|
|
import 'package:budget_app/pages/sms/widgets/sms_message_widget.dart';
|
|
import 'package:budget_app/l10n/app_localizations.dart';
|
|
|
|
/// Экран для отображения SMS сообщений.
|
|
///
|
|
/// Использует [SmsCubit] для получения и отображения
|
|
/// последних SMS сообщений.
|
|
class SmsPage extends StatelessWidget {
|
|
const SmsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(AppLocalizations.of(context)!.smsPageTitle),
|
|
),
|
|
body: BlocBuilder<SmsCubit, SmsState>(
|
|
builder: (context, state) {
|
|
if (state is SmsInitial) {
|
|
// Начальное состояние, запускаем загрузку
|
|
context.read<SmsCubit>().loadLastMessages();
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else if (state is SmsLoading) {
|
|
// Состояние загрузки
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else if (state is SmsLoaded) {
|
|
// Состояние успешной загрузки
|
|
return ListView.builder(
|
|
itemCount: state.messages.length,
|
|
itemBuilder: (context, index) {
|
|
return SmsMessageWidget(message: state.messages[index]);
|
|
},
|
|
);
|
|
} else if (state is SmsPermissionDenied) {
|
|
// Состояние отказа в разрешении
|
|
return Center(
|
|
child: Text(AppLocalizations.of(context)!.smsPermissionDenied),
|
|
);
|
|
} else if (state is SmsError) {
|
|
// Состояние ошибки
|
|
return Center(
|
|
child: Text(state.message),
|
|
);
|
|
}
|
|
return const SizedBox.shrink();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|