LCOV - code coverage report
Current view: | top level - src/providers - injected_theme_provider.dart (source / functions) |  |  | Hit | Total | Coverage
Test: | lcov.info |  | Lines: | 23 | 23 | 100.0 %
Date: | 2021-10-11 06:57:03 |  | Functions: | 0 | 0 | -

              Line data    Source code
           1             : import 'package:flutter/material.dart';
           2             : import 'package:widgetbook/src/providers/injected_theme_state.dart';
           3             : import 'package:widgetbook/src/providers/provider.dart';
           4             :
           5             : class InjectedThemeBuilder extends StatefulWidget {
           6           1 :   const InjectedThemeBuilder({
           7             :     Key? key,
           8             :     required this.child,
           9             :     this.lightTheme,
          10             :     this.darkTheme,
          11           1 :   }) : super(key: key);
          12             :
          13             :   final Widget child;
          14             :   final ThemeData? lightTheme;
          15             :   final ThemeData? darkTheme;
          16             :
          17           1 :   @override
          18           1 :   _InjectedThemeBuilderState createState() => _InjectedThemeBuilderState();
          19             : }
          20             :
          21             : class _InjectedThemeBuilderState extends State<InjectedThemeBuilder> {
          22             :   late InjectedThemeState state;
          23             :
          24           1 :   @override
          25             :   void initState() {
          26           2 :     state = InjectedThemeState(
          27           2 :       lightTheme: widget.lightTheme,
          28           2 :       darkTheme: widget.darkTheme,
          29             :     );
          30           1 :     super.initState();
          31             :   }
          32             :
          33           1 :   @override
          34             :   Widget build(BuildContext context) {
          35           1 :     return InjectedThemeProvider(
          36           1 :       state: state,
          37           1 :       onStateChanged: (InjectedThemeState state) {
          38           2 :         setState(() {
          39           1 :           this.state = state;
          40             :         });
          41             :       },
          42           2 :       child: widget.child,
          43             :     );
          44             :   }
          45             : }
          46             :
          47             : class InjectedThemeProvider extends Provider<InjectedThemeState> {
          48           1 :   const InjectedThemeProvider({
          49             :     required InjectedThemeState state,
          50             :     required ValueChanged<InjectedThemeState> onStateChanged,
          51             :     required Widget child,
          52             :     Key? key,
          53           1 :   }) : super(
          54             :           state: state,
          55             :           onStateChanged: onStateChanged,
          56             :           child: child,
          57             :           key: key,
          58             :         );
          59             :
          60           1 :   static InjectedThemeProvider? of(BuildContext context) {
          61           1 :     return context.dependOnInheritedWidgetOfExactType<InjectedThemeProvider>();
          62             :   }
          63             :
          64           1 :   void themesChanged({
          65             :     ThemeData? lightTheme,
          66             :     ThemeData? darkTheme,
          67             :   }) {
          68           1 :     emit(
          69           1 :       InjectedThemeState(
          70             :         lightTheme: lightTheme,
          71             :         darkTheme: darkTheme,
          72             :       ),
          73             :     );
          74             :   }
          75             : }

Generated by: LCOV version 1.15