Add SimDataScreen
This commit is contained in:
@@ -92,6 +92,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
appLocalization(context).profile_setting,
|
||||
userSnapshot.data ?? user),
|
||||
SizedBox(height: context.lowValue),
|
||||
cardContent(
|
||||
Icons.sim_card,
|
||||
appLocalization(context).profile_sim_data,
|
||||
userSnapshot.data ?? user),
|
||||
SizedBox(height: context.lowValue),
|
||||
cardContent(
|
||||
Icons.logout_outlined,
|
||||
appLocalization(context).log_out,
|
||||
@@ -113,7 +118,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
changeUserPassword(context, settingsBloc);
|
||||
} else if (icon == Icons.settings_outlined) {
|
||||
context.push(ApplicationConstants.DEVICE_NOTIFICATIONS_SETTINGS);
|
||||
} else {
|
||||
} else if(icon == Icons.sim_card){
|
||||
context.push(ApplicationConstants.SIM_DATA_SETTINGS);
|
||||
}
|
||||
else {
|
||||
await apiServices.logOut(context);
|
||||
}
|
||||
},
|
||||
|
||||
170
lib/feature/settings/sim_data/shared_sim_component.dart
Normal file
170
lib/feature/settings/sim_data/shared_sim_component.dart
Normal file
@@ -0,0 +1,170 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../devices/device_model.dart';
|
||||
import '../../../product/extension/context_extension.dart';
|
||||
import '../../../product/services/language_services.dart';
|
||||
|
||||
import '../../../product/utils/device_utils.dart';
|
||||
|
||||
class SharedSimComponent extends StatelessWidget {
|
||||
|
||||
const SharedSimComponent({super.key, required this.device});
|
||||
final Device device;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
double screenWidth = MediaQuery.of(context).size.width;
|
||||
double screenHeight = MediaQuery.of(context).size.height;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Container(
|
||||
width: screenWidth,
|
||||
height: screenHeight / 5.5,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
gradient: getGradientColor(getMonthLeft())
|
||||
),
|
||||
child: Padding(
|
||||
padding: context.paddingLow,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
device.name ?? "name",
|
||||
style: const TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
_buildStatusChip(context,device.state ?? -1),
|
||||
],
|
||||
),
|
||||
SizedBox(height: context.lowValue),
|
||||
// Time period
|
||||
Text(
|
||||
"${appLocalization(context).time_title}: ${convertStartTime()} - ${convertExpireTime()}",
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
SizedBox(height: context.lowValue),
|
||||
_buildDurationDisplay(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusChip(BuildContext context,int state) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.white),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.circle,
|
||||
color: DeviceUtils.instance.getTableRowColor(context, state),
|
||||
size: 12,
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
DeviceUtils.instance.checkStateDevice(context, state),
|
||||
style: TextStyle(
|
||||
color: DeviceUtils.instance.getTableRowColor(context, state),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDurationDisplay(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Text(
|
||||
"${getMonthLeft()}",
|
||||
style: const TextStyle(
|
||||
fontSize: 40,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
appLocalization(context).sim_data_month_left_message,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String convertStartTime(){
|
||||
return DateFormat('dd/MM/yyyy').format(device.createdAt!);
|
||||
}
|
||||
|
||||
String convertExpireTime() {
|
||||
final expireDate = _calculateExpireDate();
|
||||
return DateFormat('dd/MM/yyyy').format(expireDate);
|
||||
}
|
||||
|
||||
int getMonthLeft() {
|
||||
final expireDate = _calculateExpireDate();
|
||||
final now = DateTime.now();
|
||||
|
||||
int totalMonths = (expireDate.year - now.year) * 12 + (expireDate.month - now.month);
|
||||
|
||||
if (expireDate.day < now.day) {
|
||||
totalMonths -= 1;
|
||||
}
|
||||
|
||||
return totalMonths;
|
||||
}
|
||||
|
||||
DateTime _calculateExpireDate() {
|
||||
return DateTime(
|
||||
device.createdAt!.year + 3,
|
||||
device.createdAt!.month,
|
||||
device.createdAt!.day,
|
||||
device.createdAt!.hour,
|
||||
device.createdAt!.minute,
|
||||
device.createdAt!.second,
|
||||
device.createdAt!.millisecond,
|
||||
device.createdAt!.microsecond,
|
||||
);
|
||||
}
|
||||
|
||||
LinearGradient getGradientColor(int monthLeft){
|
||||
if(monthLeft <= 3){
|
||||
return const LinearGradient(
|
||||
colors: [Color(0xFFff4b1f), Color(0xFFff9068)],
|
||||
);
|
||||
}else{
|
||||
return const LinearGradient(
|
||||
colors: [Color(0xFF56ab2f), Color(0xFFa8e063)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
55
lib/feature/settings/sim_data/sim_data_screen.dart
Normal file
55
lib/feature/settings/sim_data/sim_data_screen.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sfm_app/feature/settings/sim_data/shared_sim_component.dart';
|
||||
|
||||
import '../../../product/services/language_services.dart';
|
||||
import '../../../product/shared/shared_loading_animation.dart';
|
||||
import '../../../bloc/sim_data_bloc.dart';
|
||||
import '../../../product/base/bloc/base_bloc.dart';
|
||||
|
||||
class SimDataScreen extends StatefulWidget {
|
||||
const SimDataScreen({super.key});
|
||||
@override
|
||||
State<SimDataScreen> createState() => _SimDataScreenState();
|
||||
}
|
||||
|
||||
class _SimDataScreenState extends State<SimDataScreen> {
|
||||
late SimDataBloc simDataBloc;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
simDataBloc = BlocProvider.of(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(appLocalization(context).profile_sim_data),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: StreamBuilder(
|
||||
stream: simDataBloc.streamDevices,
|
||||
builder: (context, devicesSnapshot) {
|
||||
if (devicesSnapshot.data == null) {
|
||||
simDataBloc.getOwnerDevices(context);
|
||||
return const SharedLoadingAnimation();
|
||||
} else if (devicesSnapshot.data!.isEmpty) {
|
||||
return Center(
|
||||
child: Text(appLocalization(context).main_no_data),
|
||||
);
|
||||
} else {
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
children: devicesSnapshot.data!.map(
|
||||
(device) {
|
||||
return SharedSimComponent(device: device,);
|
||||
},
|
||||
).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user