2022-10-30 18:06:51 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-06-23 08:47:34 +00:00
|
|
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
2023-06-04 11:04:04 +00:00
|
|
|
import 'package:lightmeter/utils/inherited_generics.dart';
|
2023-03-30 19:24:18 +00:00
|
|
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
2022-10-30 18:06:51 +00:00
|
|
|
|
|
|
|
class StopTypeProvider extends StatefulWidget {
|
2023-06-04 11:04:04 +00:00
|
|
|
final Widget child;
|
2022-10-30 18:06:51 +00:00
|
|
|
|
2023-06-04 11:04:04 +00:00
|
|
|
const StopTypeProvider({required this.child, super.key});
|
2022-10-30 18:06:51 +00:00
|
|
|
|
2022-12-11 14:04:08 +00:00
|
|
|
static StopTypeProviderState of(BuildContext context) {
|
|
|
|
return context.findAncestorStateOfType<StopTypeProviderState>()!;
|
|
|
|
}
|
|
|
|
|
2022-10-30 18:06:51 +00:00
|
|
|
@override
|
|
|
|
State<StopTypeProvider> createState() => StopTypeProviderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class StopTypeProviderState extends State<StopTypeProvider> {
|
2023-06-23 08:47:34 +00:00
|
|
|
late StopType _stopType;
|
2022-12-11 14:04:08 +00:00
|
|
|
|
2023-06-23 08:47:34 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_stopType = context.get<UserPreferencesService>().stopType;
|
2022-12-11 14:04:08 +00:00
|
|
|
}
|
2022-10-30 18:06:51 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-06-04 11:04:04 +00:00
|
|
|
return InheritedWidgetBase<StopType>(
|
|
|
|
data: _stopType,
|
2022-12-11 14:04:08 +00:00
|
|
|
child: widget.child,
|
2022-10-30 18:06:51 +00:00
|
|
|
);
|
|
|
|
}
|
2023-06-23 08:47:34 +00:00
|
|
|
|
|
|
|
void set(StopType type) {
|
|
|
|
setState(() {
|
|
|
|
_stopType = type;
|
|
|
|
});
|
|
|
|
context.get<UserPreferencesService>().stopType = type;
|
|
|
|
}
|
2022-10-30 18:06:51 +00:00
|
|
|
}
|