|
1 | | -import 'dart:convert'; |
2 | | - |
3 | 1 | import 'package:flutter/material.dart'; |
4 | 2 | import 'package:flutter/services.dart'; |
5 | 3 |
|
6 | | -import '../models/control.dart'; |
7 | 4 | import '../utils/numbers.dart'; |
8 | 5 | import 'colors.dart'; |
9 | 6 |
|
10 | | -SystemUiOverlayStyle? parseSystemOverlayStyle( |
11 | | - ThemeData theme, Control control, String propName) { |
12 | | - dynamic j; |
13 | | - var v = control.attrString(propName, null); |
14 | | - if (v == null) { |
15 | | - return null; |
16 | | - } |
17 | | - j = json.decode(v); |
18 | | - return overlayStyleFromJson(theme, j); |
19 | | -} |
20 | | - |
21 | 7 | SystemUiOverlayStyle overlayStyleFromJson( |
22 | | - ThemeData theme, Map<String, dynamic> json) { |
| 8 | + ThemeData? theme, Map<String, dynamic> json, Brightness? brightness) { |
23 | 9 | return SystemUiOverlayStyle( |
24 | | - statusBarColor: json["status_bar_color"] != null |
25 | | - ? HexColor.fromString(theme, json["status_bar_color"] ?? "") |
26 | | - : null, |
27 | | - systemNavigationBarColor: json["system_navigation_bar_color"] != null |
28 | | - ? HexColor.fromString(theme, json["system_navigation_bar_color"] ?? "") |
29 | | - : null, |
30 | | - systemNavigationBarDividerColor: |
31 | | - json["system_navigation_bar_divider_color"] != null |
32 | | - ? HexColor.fromString(theme, json["system_navigation_bar_divider_color"] ?? "") |
33 | | - : null, |
34 | | - systemStatusBarContrastEnforced: |
35 | | - json["enforce_system_status_bar_contrast"] != null |
36 | | - ? parseBool(json["enforce_system_status_bar_contrast"]) |
37 | | - : null, |
38 | | - systemNavigationBarContrastEnforced: |
39 | | - json["enforce_system_navigation_bar_contrast"] != null |
40 | | - ? parseBool(json["enforce_system_navigation_bar_contrast"]) |
41 | | - : null, |
42 | | - ); |
| 10 | + statusBarColor: json["status_bar_color"] != null |
| 11 | + ? HexColor.fromString(theme, json["status_bar_color"] ?? "") |
| 12 | + : null, |
| 13 | + systemNavigationBarColor: json["system_navigation_bar_color"] != null |
| 14 | + ? HexColor.fromString( |
| 15 | + theme, json["system_navigation_bar_color"] ?? "") |
| 16 | + : null, |
| 17 | + systemNavigationBarDividerColor: |
| 18 | + json["system_navigation_bar_divider_color"] != null |
| 19 | + ? HexColor.fromString( |
| 20 | + theme, json["system_navigation_bar_divider_color"] ?? "") |
| 21 | + : null, |
| 22 | + systemStatusBarContrastEnforced: |
| 23 | + json["enforce_system_status_bar_contrast"] != null |
| 24 | + ? parseBool(json["enforce_system_status_bar_contrast"]) |
| 25 | + : null, |
| 26 | + systemNavigationBarContrastEnforced: |
| 27 | + json["enforce_system_navigation_bar_contrast"] != null |
| 28 | + ? parseBool(json["enforce_system_navigation_bar_contrast"]) |
| 29 | + : null, |
| 30 | + systemNavigationBarIconBrightness: parseBrightness( |
| 31 | + json["system_navigation_bar_icon_brightness"], brightness), |
| 32 | + statusBarBrightness: |
| 33 | + parseBrightness(json["status_bar_brightness"], brightness), |
| 34 | + statusBarIconBrightness: |
| 35 | + parseBrightness(json["status_bar_icon_brightness"], brightness)); |
| 36 | +} |
| 37 | + |
| 38 | +Brightness? parseBrightness(dynamic value, Brightness? brightness) { |
| 39 | + if (value == null) { |
| 40 | + return null; |
| 41 | + } |
| 42 | + var b = parseBool(value); |
| 43 | + Brightness? invertedBrightness = brightness != null |
| 44 | + ? brightness == Brightness.light |
| 45 | + ? Brightness.dark |
| 46 | + : Brightness.light |
| 47 | + : null; |
| 48 | + return b ? brightness : invertedBrightness; |
43 | 49 | } |
0 commit comments