non-null EquipmentProfile

This commit is contained in:
Vadim 2023-03-23 23:23:26 +03:00
parent 96b7ec0440
commit eb78b0b80b
8 changed files with 21 additions and 22 deletions

View file

@ -88,11 +88,11 @@ class EquipmentProfiles extends InheritedWidget {
super.key,
});
static List<EquipmentProfileData>? of(BuildContext context, {bool listen = true}) {
static List<EquipmentProfileData> of(BuildContext context, {bool listen = true}) {
if (listen) {
return context.dependOnInheritedWidgetOfExactType<EquipmentProfiles>()?.profiles;
return context.dependOnInheritedWidgetOfExactType<EquipmentProfiles>()!.profiles;
} else {
return context.findAncestorWidgetOfExactType<EquipmentProfiles>()?.profiles;
return context.findAncestorWidgetOfExactType<EquipmentProfiles>()!.profiles;
}
}
@ -101,7 +101,7 @@ class EquipmentProfiles extends InheritedWidget {
}
class EquipmentProfile extends InheritedWidget {
final EquipmentProfileData? data;
final EquipmentProfileData data;
const EquipmentProfile({
required this.data,
@ -109,11 +109,11 @@ class EquipmentProfile extends InheritedWidget {
super.key,
});
static EquipmentProfileData? of(BuildContext context, {bool listen = true}) {
static EquipmentProfileData of(BuildContext context, {bool listen = true}) {
if (listen) {
return context.dependOnInheritedWidgetOfExactType<EquipmentProfile>()?.data;
return context.dependOnInheritedWidgetOfExactType<EquipmentProfile>()!.data;
} else {
return context.findAncestorWidgetOfExactType<EquipmentProfile>()?.data;
return context.findAncestorWidgetOfExactType<EquipmentProfile>()!.data;
}
}

View file

@ -40,9 +40,9 @@ class CameraContainerProvider extends StatelessWidget {
child: CameraContainer(
fastest: fastest,
slowest: slowest,
isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues,
isoValues: EquipmentProfile.of(context).isoValues,
iso: iso,
ndValues: EquipmentProfile.of(context)?.ndValues ?? ndValues,
ndValues: EquipmentProfile.of(context).ndValues,
nd: nd,
onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged,

View file

@ -49,7 +49,7 @@ class CameraContainer extends StatelessWidget {
PlatformConfig.cameraPreviewAspectRatio;
double topBarOverflow = Dimens.readingContainerDefaultHeight - cameraViewHeight;
if (EquipmentProfiles.of(context)?.isNotEmpty ?? false) {
if (EquipmentProfiles.of(context).isNotEmpty) {
topBarOverflow += Dimens.readingContainerSingleValueHeight;
topBarOverflow += Dimens.paddingS;
}

View file

@ -40,9 +40,9 @@ class LightSensorContainerProvider extends StatelessWidget {
child: LightSensorContainer(
fastest: fastest,
slowest: slowest,
isoValues: EquipmentProfile.of(context)?.isoValues ?? isoValues,
isoValues: EquipmentProfile.of(context).isoValues,
iso: iso,
ndValues: EquipmentProfile.of(context)?.ndValues ?? ndValues,
ndValues: EquipmentProfile.of(context).ndValues,
nd: nd,
onIsoChanged: onIsoChanged,
onNdChanged: onNdChanged,

View file

@ -36,11 +36,10 @@ class ReadingsContainer extends StatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (EquipmentProfile.of(context) != null &&
(EquipmentProfiles.of(context)?.isNotEmpty ?? false)) ...[
if (EquipmentProfiles.of(context).isNotEmpty) ...[
_EquipmentProfilePicker(
selectedValue: EquipmentProfile.of(context)!,
values: EquipmentProfiles.of(context)!,
selectedValue: EquipmentProfile.of(context),
values: EquipmentProfiles.of(context),
onChanged: EquipmentProfileProvider.of(context).setProfile,
),
const _InnerPadding(),

View file

@ -40,7 +40,7 @@ class _MeteringFlowState extends State<MeteringFlow> {
context.read<MeteringCommunicationBloc>(),
context.read<UserPreferencesService>(),
context.read<MeteringInteractor>(),
EquipmentProfile.of(context, listen: false)!,
EquipmentProfile.of(context, listen: false),
context.read<StopType>(),
),
),

View file

@ -27,7 +27,7 @@ class _MeteringScreenState extends State<MeteringScreen> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
_bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)!));
_bloc.add(EquipmentProfileChangedEvent(EquipmentProfile.of(context)));
_bloc.add(StopTypeChangedEvent(context.watch<StopType>()));
}

View file

@ -18,13 +18,13 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
static const maxProfiles = 5; // replace with a constant from iap
late List<GlobalKey<EquipmentProfileContainerState>> profileContainersKeys = [];
int get profilesCount => EquipmentProfiles.of(context)?.length ?? 0;
int get profilesCount => EquipmentProfiles.of(context).length;
@override
void initState() {
super.initState();
profileContainersKeys = List.filled(
EquipmentProfiles.of(context, listen: false)?.length ?? 0,
EquipmentProfiles.of(context, listen: false).length,
GlobalKey<EquipmentProfileContainerState>(),
growable: true,
);
@ -56,7 +56,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
itemBuilder: (context, index) => index > 0
? EquipmentProfileContainer(
key: profileContainersKeys[index],
data: EquipmentProfiles.of(context)![index],
data: EquipmentProfiles.of(context)[index],
onExpand: () => _keepExpandedAt(index),
onUpdate: (profileData) => _updateProfileAt(profileData, index),
onDelete: () => _removeProfileAt(index),
@ -91,7 +91,7 @@ class _EquipmentProfilesScreenState extends State<EquipmentProfilesScreen> {
}
void _removeProfileAt(int index) {
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)![index]);
EquipmentProfileProvider.of(context).deleteProfile(EquipmentProfiles.of(context)[index]);
profileContainersKeys.removeAt(index);
}