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 {
|
class Application extends StatelessWidget {
|
||||||
final Environment env;
|
final Environment env;
|
||||||
|
|
||||||
const Application(this.env, {super.key});
|
Application(this.env, {super.key});
|
||||||
|
|
||||||
|
final RouteObserver<ModalRoute> routeObserver = RouteObserver<ModalRoute>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -30,15 +32,19 @@ class Application extends StatelessWidget {
|
||||||
GlobalCupertinoLocalizations.delegate,
|
GlobalCupertinoLocalizations.delegate,
|
||||||
],
|
],
|
||||||
supportedLocales: S.delegate.supportedLocales,
|
supportedLocales: S.delegate.supportedLocales,
|
||||||
builder: (context, child) => MediaQuery(
|
builder: (context, child) => InheritedWidgetBase<RouteObserver<ModalRoute>>(
|
||||||
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
data: routeObserver,
|
||||||
child: child!,
|
child: MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
|
||||||
|
child: child!,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
initialRoute: "metering",
|
initialRoute: "metering",
|
||||||
routes: {
|
routes: {
|
||||||
"metering": (context) => const MeteringFlow(),
|
"metering": (context) => const MeteringFlow(),
|
||||||
"settings": (context) => const SettingsFlow(),
|
"settings": (context) => const SettingsFlow(),
|
||||||
},
|
},
|
||||||
|
navigatorObservers: [routeObserver],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: const SizedBox(),
|
: const SizedBox(),
|
||||||
|
|
|
@ -4,5 +4,5 @@ import 'package:lightmeter/environment.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
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 {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await initializeFirebase();
|
await initializeFirebase();
|
||||||
|
runApp(Application(const Environment.prod()));
|
||||||
runApp(const Application(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/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/metering_top_bar/widget_top_bar_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/widget_container_readings.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';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class CameraContainer extends StatelessWidget {
|
class CameraContainer extends StatefulWidget {
|
||||||
final ExposurePair? fastest;
|
final ExposurePair? fastest;
|
||||||
final ExposurePair? slowest;
|
final ExposurePair? slowest;
|
||||||
final Film film;
|
final Film film;
|
||||||
|
@ -44,6 +45,29 @@ class CameraContainer extends StatelessWidget {
|
||||||
super.key,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final double cameraViewHeight =
|
final double cameraViewHeight =
|
||||||
|
@ -75,14 +99,14 @@ class CameraContainer extends StatelessWidget {
|
||||||
children: [
|
children: [
|
||||||
MeteringTopBar(
|
MeteringTopBar(
|
||||||
readingsContainer: ReadingsContainer(
|
readingsContainer: ReadingsContainer(
|
||||||
fastest: fastest,
|
fastest: widget.fastest,
|
||||||
slowest: slowest,
|
slowest: widget.slowest,
|
||||||
film: film,
|
film: widget.film,
|
||||||
iso: iso,
|
iso: widget.iso,
|
||||||
nd: nd,
|
nd: widget.nd,
|
||||||
onFilmChanged: onFilmChanged,
|
onFilmChanged: widget.onFilmChanged,
|
||||||
onIsoChanged: onIsoChanged,
|
onIsoChanged: widget.onIsoChanged,
|
||||||
onNdChanged: onNdChanged,
|
onNdChanged: widget.onNdChanged,
|
||||||
),
|
),
|
||||||
appendixHeight: topBarOverflow,
|
appendixHeight: topBarOverflow,
|
||||||
preview: const _CameraViewBuilder(),
|
preview: const _CameraViewBuilder(),
|
||||||
|
@ -92,7 +116,7 @@ class CameraContainer extends StatelessWidget {
|
||||||
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||||
child: _MiddleContentWrapper(
|
child: _MiddleContentWrapper(
|
||||||
topBarOverflow: topBarOverflow,
|
topBarOverflow: topBarOverflow,
|
||||||
leftContent: ExposurePairsList(exposurePairs),
|
leftContent: ExposurePairsList(widget.exposurePairs),
|
||||||
rightContent: const _CameraControlsBuilder(),
|
rightContent: const _CameraControlsBuilder(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -26,6 +26,7 @@ class LightSensorContainerBloc
|
||||||
const LightSensorContainerState(null),
|
const LightSensorContainerState(null),
|
||||||
) {
|
) {
|
||||||
on<LuxMeteringEvent>(_onLuxMeteringEvent);
|
on<LuxMeteringEvent>(_onLuxMeteringEvent);
|
||||||
|
on<CancelLuxMeteringEvent>(_onCancelLuxMeteringEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -51,6 +52,10 @@ class LightSensorContainerBloc
|
||||||
communicationBloc.add(communication_event.MeteringInProgressEvent(ev100));
|
communicationBloc.add(communication_event.MeteringInProgressEvent(ev100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onCancelLuxMeteringEvent(CancelLuxMeteringEvent event, _) {
|
||||||
|
_cancelMetering();
|
||||||
|
}
|
||||||
|
|
||||||
void _startMetering() {
|
void _startMetering() {
|
||||||
_luxSubscriptions = _meteringInteractor.luxStream().listen((lux) => add(LuxMeteringEvent(lux)));
|
_luxSubscriptions = _meteringInteractor.luxStream().listen((lux) => add(LuxMeteringEvent(lux)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,3 +7,7 @@ class LuxMeteringEvent extends LightSensorContainerEvent {
|
||||||
|
|
||||||
const LuxMeteringEvent(this.lux);
|
const LuxMeteringEvent(this.lux);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CancelLuxMeteringEvent extends LightSensorContainerEvent {
|
||||||
|
const CancelLuxMeteringEvent();
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
import 'package:flutter/material.dart';
|
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/exposure_pair.dart';
|
||||||
import 'package:lightmeter/data/models/film.dart';
|
import 'package:lightmeter/data/models/film.dart';
|
||||||
import 'package:lightmeter/res/dimens.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/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/metering_top_bar/widget_top_bar_metering.dart';
|
||||||
import 'package:lightmeter/screens/metering/components/shared/readings_container/widget_container_readings.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';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
|
|
||||||
class LightSensorContainer extends StatelessWidget {
|
class LightSensorContainer extends StatefulWidget {
|
||||||
final ExposurePair? fastest;
|
final ExposurePair? fastest;
|
||||||
final ExposurePair? slowest;
|
final ExposurePair? slowest;
|
||||||
final Film film;
|
final Film film;
|
||||||
|
@ -31,26 +35,43 @@ class LightSensorContainer extends StatelessWidget {
|
||||||
super.key,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
MeteringTopBar(
|
MeteringTopBar(
|
||||||
readingsContainer: ReadingsContainer(
|
readingsContainer: ReadingsContainer(
|
||||||
fastest: fastest,
|
fastest: widget.fastest,
|
||||||
slowest: slowest,
|
slowest: widget.slowest,
|
||||||
film: film,
|
film: widget.film,
|
||||||
iso: iso,
|
iso: widget.iso,
|
||||||
nd: nd,
|
nd: widget.nd,
|
||||||
onFilmChanged: onFilmChanged,
|
onFilmChanged: widget.onFilmChanged,
|
||||||
onIsoChanged: onIsoChanged,
|
onIsoChanged: widget.onIsoChanged,
|
||||||
onNdChanged: onNdChanged,
|
onNdChanged: widget.onNdChanged,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
padding: const EdgeInsets.symmetric(horizontal: Dimens.paddingM),
|
||||||
child: Center(child: ExposurePairsList(exposurePairs)),
|
child: Center(child: ExposurePairsList(widget.exposurePairs)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue