mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-25 17:00:39 +00:00
deinitialize camera when on Settings screen
This commit is contained in:
parent
dc53982ebb
commit
1b19b417dc
7 changed files with 86 additions and 27 deletions
|
@ -12,7 +12,9 @@ import 'package:lightmeter/utils/inherited_generics.dart';
|
|||
class Application extends StatelessWidget {
|
||||
final Environment env;
|
||||
|
||||
const Application(this.env, {super.key});
|
||||
Application(this.env, {super.key});
|
||||
|
||||
final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -30,15 +32,19 @@ class Application extends StatelessWidget {
|
|||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: child!,
|
||||
builder: (context, child) => InheritedWidgetBase<RouteObserver<ModalRoute>>(
|
||||
data: routeObserver,
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
initialRoute: "metering",
|
||||
routes: {
|
||||
"metering": (context) => const MeteringFlow(),
|
||||
"settings": (context) => const SettingsFlow(),
|
||||
},
|
||||
navigatorObservers: [routeObserver],
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
|
|
|
@ -4,5 +4,5 @@ import 'package:lightmeter/environment.dart';
|
|||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
runApp(const Application(Environment.dev()));
|
||||
runApp(Application(const Environment.dev()));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,5 @@ import 'package:lightmeter/firebase.dart';
|
|||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await initializeFirebase();
|
||||
|
||||
runApp(const Application(Environment.prod()));
|
||||
runApp(Application(const Environment.prod()));
|
||||
}
|
||||
|
|
|
@ -18,9 +18,10 @@ import 'package:lightmeter/screens/metering/components/camera_container/state_co
|
|||
import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
|
||||
import 'package:lightmeter/screens/metering/components/shared/metering_top_bar/widget_top_bar_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/widget_container_readings.dart';
|
||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
|
||||
class CameraContainer extends StatelessWidget {
|
||||
class CameraContainer extends StatefulWidget {
|
||||
final ExposurePair? fastest;
|
||||
final ExposurePair? slowest;
|
||||
final Film film;
|
||||
|
@ -44,6 +45,29 @@ class CameraContainer extends StatelessWidget {
|
|||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CameraContainer> createState() => _CameraContainerState();
|
||||
}
|
||||
|
||||
class _CameraContainerState extends State<CameraContainer> with RouteAware {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
context.get<RouteObserver<ModalRoute>>().subscribe(this, ModalRoute.of(context)!);
|
||||
}
|
||||
|
||||
@override
|
||||
void didPushNext() {
|
||||
super.didPushNext();
|
||||
context.read<CameraContainerBloc>().add(const DeinitializeEvent());
|
||||
}
|
||||
|
||||
@override
|
||||
void didPopNext() {
|
||||
super.didPopNext();
|
||||
context.read<CameraContainerBloc>().add(const InitializeEvent());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final double cameraViewHeight =
|
||||
|
@ -75,14 +99,14 @@ class CameraContainer extends StatelessWidget {
|
|||
children: [
|
||||
MeteringTopBar(
|
||||
readingsContainer: ReadingsContainer(
|
||||
fastest: fastest,
|
||||
slowest: slowest,
|
||||
film: film,
|
||||
iso: iso,
|
||||
nd: nd,
|
||||
onFilmChanged: onFilmChanged,
|
||||
onIsoChanged: onIsoChanged,
|
||||
onNdChanged: onNdChanged,
|
||||
fastest: widget.fastest,
|
||||
slowest: widget.slowest,
|
||||
film: widget.film,
|
||||
iso: widget.iso,
|
||||
nd: widget.nd,
|
||||
onFilmChanged: widget.onFilmChanged,
|
||||
onIsoChanged: widget.onIsoChanged,
|
||||
onNdChanged: widget.onNdChanged,
|
||||
),
|
||||
appendixHeight: topBarOverflow,
|
||||
preview: const _CameraViewBuilder(),
|
||||
|
@ -92,7 +116,7 @@ class CameraContainer extends StatelessWidget {
|
|||
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||
child: _MiddleContentWrapper(
|
||||
topBarOverflow: topBarOverflow,
|
||||
leftContent: ExposurePairsList(exposurePairs),
|
||||
leftContent: ExposurePairsList(widget.exposurePairs),
|
||||
rightContent: const _CameraControlsBuilder(),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -26,6 +26,7 @@ class LightSensorContainerBloc
|
|||
const LightSensorContainerState(null),
|
||||
) {
|
||||
on<LuxMeteringEvent>(_onLuxMeteringEvent);
|
||||
on<CancelLuxMeteringEvent>(_onCancelLuxMeteringEvent);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -51,6 +52,10 @@ class LightSensorContainerBloc
|
|||
communicationBloc.add(communication_event.MeteringInProgressEvent(ev100));
|
||||
}
|
||||
|
||||
void _onCancelLuxMeteringEvent(CancelLuxMeteringEvent event, _) {
|
||||
_cancelMetering();
|
||||
}
|
||||
|
||||
void _startMetering() {
|
||||
_luxSubscriptions = _meteringInteractor.luxStream().listen((lux) => add(LuxMeteringEvent(lux)));
|
||||
}
|
||||
|
|
|
@ -7,3 +7,7 @@ class LuxMeteringEvent extends LightSensorContainerEvent {
|
|||
|
||||
const LuxMeteringEvent(this.lux);
|
||||
}
|
||||
|
||||
class CancelLuxMeteringEvent extends LightSensorContainerEvent {
|
||||
const CancelLuxMeteringEvent();
|
||||
}
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:lightmeter/data/models/exposure_pair.dart';
|
||||
import 'package:lightmeter/data/models/film.dart';
|
||||
import 'package:lightmeter/res/dimens.dart';
|
||||
import 'package:lightmeter/screens/metering/components/light_sensor_container/bloc_container_light_sensor.dart';
|
||||
import 'package:lightmeter/screens/metering/components/light_sensor_container/event_container_light_sensor.dart';
|
||||
import 'package:lightmeter/screens/metering/components/shared/exposure_pairs_list/widget_list_exposure_pairs.dart';
|
||||
import 'package:lightmeter/screens/metering/components/shared/metering_top_bar/widget_top_bar_metering.dart';
|
||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/widget_container_readings.dart';
|
||||
import 'package:lightmeter/utils/inherited_generics.dart';
|
||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||
|
||||
class LightSensorContainer extends StatelessWidget {
|
||||
class LightSensorContainer extends StatefulWidget {
|
||||
final ExposurePair? fastest;
|
||||
final ExposurePair? slowest;
|
||||
final Film film;
|
||||
|
@ -31,26 +35,43 @@ class LightSensorContainer extends StatelessWidget {
|
|||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<LightSensorContainer> createState() => _LightSensorContainerState();
|
||||
}
|
||||
|
||||
class _LightSensorContainerState extends State<LightSensorContainer> with RouteAware {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
context.get<RouteObserver<ModalRoute>>().subscribe(this, ModalRoute.of(context)!);
|
||||
}
|
||||
|
||||
@override
|
||||
void didPushNext() {
|
||||
super.didPushNext();
|
||||
context.read<LightSensorContainerBloc>().add(const CancelLuxMeteringEvent());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
MeteringTopBar(
|
||||
readingsContainer: ReadingsContainer(
|
||||
fastest: fastest,
|
||||
slowest: slowest,
|
||||
film: film,
|
||||
iso: iso,
|
||||
nd: nd,
|
||||
onFilmChanged: onFilmChanged,
|
||||
onIsoChanged: onIsoChanged,
|
||||
onNdChanged: onNdChanged,
|
||||
fastest: widget.fastest,
|
||||
slowest: widget.slowest,
|
||||
film: widget.film,
|
||||
iso: widget.iso,
|
||||
nd: widget.nd,
|
||||
onFilmChanged: widget.onFilmChanged,
|
||||
onIsoChanged: widget.onIsoChanged,
|
||||
onNdChanged: widget.onNdChanged,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||
child: Center(child: ExposurePairsList(exposurePairs)),
|
||||
child: Center(child: ExposurePairsList(widget.exposurePairs)),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue