LCOV - code coverage report
Current view: | top level - src/providers - theme_provider.dart (source / functions) |  |  | Hit | Total | Coverage
Test: | lcov.info |  | Lines: | 20 | 20 | 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/provider.dart';
           3             :
           4             : class ThemeBuilder extends StatefulWidget {
           5           1 :   const ThemeBuilder({
           6             :     Key? key,
           7             :     required this.child,
           8           1 :   }) : super(key: key);
           9             :
          10             :   final Widget child;
          11             :
          12           1 :   @override
          13           1 :   _ThemeBuilderState createState() => _ThemeBuilderState();
          14             : }
          15             :
          16             : class _ThemeBuilderState extends State<ThemeBuilder> {
          17             :   ThemeMode state = ThemeMode.dark;
          18             :
          19           1 :   @override
          20             :   Widget build(BuildContext context) {
          21           1 :     return ThemeProvider(
          22           1 :       state: state,
          23           1 :       onStateChanged: (ThemeMode state) {
          24           2 :         setState(() {
          25           1 :           this.state = state;
          26             :         });
          27             :       },
          28           2 :       child: widget.child,
          29             :     );
          30             :   }
          31             : }
          32             :
          33             : class ThemeProvider extends Provider<ThemeMode> {
          34           1 :   const ThemeProvider({
          35             :     required ThemeMode state,
          36             :     required ValueChanged<ThemeMode> onStateChanged,
          37             :     required Widget child,
          38             :     Key? key,
          39           1 :   }) : super(
          40             :             state: state,
          41             :             onStateChanged: onStateChanged,
          42             :             child: child,
          43             :             key: key);
          44             :
          45           1 :   static ThemeProvider? of(BuildContext context) {
          46           1 :     return context.dependOnInheritedWidgetOfExactType<ThemeProvider>();
          47             :   }
          48             :
          49           1 :   void toggleTheme() {
          50           1 :     switch (state) {
          51           1 :       case ThemeMode.light:
          52           1 :         emit(ThemeMode.dark);
          53             :         break;
          54             :       default:
          55           1 :         emit(ThemeMode.light);
          56             :     }
          57             :   }
          58             : }

Generated by: LCOV version 1.15