m3_lightmeter/lib/providers/stop_type_provider.dart
Vadim 2735f0b66f
ML-81 Unsaved fractional stops (#83)
* save stop type to sharedPrefs

* tests
2023-06-23 10:47:34 +02:00

42 lines
1.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
class StopTypeProvider extends StatefulWidget {
final Widget child;
const StopTypeProvider({required this.child, super.key});
static StopTypeProviderState of(BuildContext context) {
return context.findAncestorStateOfType<StopTypeProviderState>()!;
}
@override
State<StopTypeProvider> createState() => StopTypeProviderState();
}
class StopTypeProviderState extends State<StopTypeProvider> {
late StopType _stopType;
@override
void initState() {
super.initState();
_stopType = context.get<UserPreferencesService>().stopType;
}
@override
Widget build(BuildContext context) {
return InheritedWidgetBase<StopType>(
data: _stopType,
child: widget.child,
);
}
void set(StopType type) {
setState(() {
_stopType = type;
});
context.get<UserPreferencesService>().stopType = type;
}
}