From a621002ad11c7c1aa160a4935fedc843f603234a Mon Sep 17 00:00:00 2001 From: Narek Date: Sat, 27 Mar 2021 20:52:14 +0400 Subject: [PATCH 1/3] migrate-null-safety --- example/lib/main.dart | 62 ++++++++++++++++-------------- lib/flutter_statusbar_manager.dart | 6 +-- pubspec.yaml | 2 +- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 909ea02..50c112a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -19,9 +19,9 @@ class MyApp extends StatefulWidget { } class _MyAppState extends State { - double _statusBarHeight = 0.0; + double? _statusBarHeight = 0.0; bool _statusBarColorAnimated = false; - Color _statusBarColor = Colors.black; + Color? _statusBarColor = Colors.black; double _statusBarOpacity = 1.0; bool _statusBarHidden = false; StatusBarAnimation _statusBarAnimation = StatusBarAnimation.NONE; @@ -31,8 +31,8 @@ class _MyAppState extends State { bool _fullscreenMode = false; bool _navBarColorAnimated = false; - Color _navBarColor = Colors.black; - NavigationBarStyle _navBarStyle = NavigationBarStyle.DEFAULT; + Color? _navBarColor = Colors.black; + NavigationBarStyle? _navBarStyle = NavigationBarStyle.DEFAULT; @override void initState() { @@ -42,7 +42,7 @@ class _MyAppState extends State { // Platform messages are asynchronous, so we initialize in an async method. Future initPlatformState() async { - double statusBarHeight; + double? statusBarHeight; // Platform messages may fail, so we use a try/catch PlatformException. try { statusBarHeight = await FlutterStatusbarManager.getHeight; @@ -70,7 +70,7 @@ class _MyAppState extends State { void updateStatusBar() { FlutterStatusbarManager.setColor( - _statusBarColor.withOpacity(_statusBarOpacity), + _statusBarColor!.withOpacity(_statusBarOpacity), animated: _statusBarColorAnimated); } @@ -95,7 +95,7 @@ class _MyAppState extends State { } void updateNavBar() { - FlutterStatusbarManager.setNavigationBarColor(_navBarColor, + FlutterStatusbarManager.setNavigationBarColor(_navBarColor!, animated: _navBarColorAnimated); } @@ -134,25 +134,25 @@ class _MyAppState extends State { RadioListTile( value: Colors.black, title: Text("Black"), - onChanged: colorBarChanged, + onChanged: (Color? v) => colorBarChanged(v!), dense: true, groupValue: _statusBarColor), RadioListTile( value: Colors.orange, title: Text("Orange"), - onChanged: colorBarChanged, + onChanged: (Color? v) => colorBarChanged(v!), dense: true, groupValue: _statusBarColor), RadioListTile( value: Colors.greenAccent, title: Text("Green"), - onChanged: colorBarChanged, + onChanged: (Color? v) => colorBarChanged(v!), dense: true, groupValue: _statusBarColor), RadioListTile( value: Colors.white30, title: Text("White"), - onChanged: colorBarChanged, + onChanged: (Color? v) => colorBarChanged(v!), dense: true, groupValue: _statusBarColor), Text("Opacity:"), @@ -184,19 +184,22 @@ class _MyAppState extends State { RadioListTile( value: StatusBarAnimation.NONE, title: Text("NONE"), - onChanged: statusBarAnimationChanged, + onChanged: (StatusBarAnimation? v) => + statusBarAnimationChanged(v!), dense: true, groupValue: _statusBarAnimation), RadioListTile( value: StatusBarAnimation.FADE, title: Text("FADE"), - onChanged: statusBarAnimationChanged, + onChanged: (StatusBarAnimation? v) => + statusBarAnimationChanged(v!), dense: true, groupValue: _statusBarAnimation), RadioListTile( value: StatusBarAnimation.SLIDE, title: Text("SLIDE"), - onChanged: statusBarAnimationChanged, + onChanged: (StatusBarAnimation? v) => + statusBarAnimationChanged(v!), dense: true, groupValue: _statusBarAnimation), Divider(height: 25.0), @@ -204,19 +207,19 @@ class _MyAppState extends State { RadioListTile( value: StatusBarStyle.DEFAULT, title: Text("DEFAULT"), - onChanged: statusBarStyleChanged, + onChanged: (StatusBarStyle? v) => statusBarStyleChanged(v!), dense: true, groupValue: _statusBarStyle), RadioListTile( value: StatusBarStyle.LIGHT_CONTENT, title: Text("LIGHT_CONTENT"), - onChanged: statusBarStyleChanged, + onChanged: (StatusBarStyle? v) => statusBarStyleChanged(v!), dense: true, groupValue: _statusBarStyle), RadioListTile( value: StatusBarStyle.DARK_CONTENT, title: Text("DARK_CONTENT"), - onChanged: statusBarStyleChanged, + onChanged: (StatusBarStyle? v) => statusBarStyleChanged(v!), dense: true, groupValue: _statusBarStyle), Divider(height: 25.0), @@ -228,8 +231,8 @@ class _MyAppState extends State { this.setState(() { _statusBarTranslucent = val; }); - FlutterStatusbarManager - .setTranslucent(_statusBarTranslucent); + FlutterStatusbarManager.setTranslucent( + _statusBarTranslucent); }, ), Divider(height: 25.0), @@ -241,8 +244,8 @@ class _MyAppState extends State { this.setState(() { _loadingIndicator = val; }); - FlutterStatusbarManager - .setNetworkActivityIndicatorVisible(_loadingIndicator); + FlutterStatusbarManager.setNetworkActivityIndicatorVisible( + _loadingIndicator); }, ), Divider(height: 25.0), @@ -260,25 +263,25 @@ class _MyAppState extends State { RadioListTile( value: Colors.black, title: Text("Black"), - onChanged: colorNavBarChanged, + onChanged: (Color? v) => colorNavBarChanged(v!), dense: true, groupValue: _navBarColor), RadioListTile( value: Colors.orange, title: Text("Orange"), - onChanged: colorNavBarChanged, + onChanged: (Color? v) => colorNavBarChanged(v!), dense: true, groupValue: _navBarColor), RadioListTile( value: Colors.greenAccent, title: Text("Green"), - onChanged: colorNavBarChanged, + onChanged: (Color? v) => colorNavBarChanged(v!), dense: true, groupValue: _navBarColor), RadioListTile( value: Colors.white12, title: Text("white"), - onChanged: colorNavBarChanged, + onChanged: (Color? v) => colorNavBarChanged(v!), dense: true, groupValue: _navBarColor), Divider(height: 25.0), @@ -286,19 +289,22 @@ class _MyAppState extends State { RadioListTile( value: NavigationBarStyle.DEFAULT, title: Text("DEFAULT"), - onChanged: navigationBarStyleChanged, + onChanged: (NavigationBarStyle? v) => + navigationBarStyleChanged(v!), dense: true, groupValue: _navBarStyle), RadioListTile( value: NavigationBarStyle.LIGHT, title: Text("LIGHT"), - onChanged: navigationBarStyleChanged, + onChanged: (NavigationBarStyle? v) => + navigationBarStyleChanged(v!), dense: true, groupValue: _navBarStyle), RadioListTile( value: NavigationBarStyle.DARK, title: Text("DARK"), - onChanged: navigationBarStyleChanged, + onChanged: (NavigationBarStyle? v) => + navigationBarStyleChanged(v!), dense: true, groupValue: _navBarStyle), Divider(height: 25.0), diff --git a/lib/flutter_statusbar_manager.dart b/lib/flutter_statusbar_manager.dart index f3b87a8..e9a3e12 100644 --- a/lib/flutter_statusbar_manager.dart +++ b/lib/flutter_statusbar_manager.dart @@ -9,7 +9,7 @@ class _StatusBarStyle { static const String LIGHT_CONTENT = "light-content"; static const String DARK_CONTENT = "dark-content"; - static String getStyle(StatusBarStyle style) { + static String getStyle(StatusBarStyle? style) { switch (style) { case StatusBarStyle.DEFAULT: return DEFAULT; @@ -30,7 +30,7 @@ class _StatusBarAnimation { static const String FADE = "fade"; static const String SLIDE = "slide"; - static String getAnimation(StatusBarAnimation animation) { + static String getAnimation(StatusBarAnimation? animation) { switch (animation) { case StatusBarAnimation.NONE: return NONE; @@ -51,7 +51,7 @@ class _NavigationBarStyle { static const String DARK = "light"; static const String LIGHT = "dark"; - static String getStyle(NavigationBarStyle style) { + static String getStyle(NavigationBarStyle? style) { switch (style) { case NavigationBarStyle.DEFAULT: return DEFAULT; diff --git a/pubspec.yaml b/pubspec.yaml index ee30e55..4868835 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,7 @@ dependencies: sdk: flutter environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' flutter: ">=1.12.0 <2.0.0" dev_dependencies: From 02464cb664218d4b145a13cb2ba5867b1a9f4703 Mon Sep 17 00:00:00 2001 From: Narek Date: Wed, 31 Mar 2021 13:44:39 +0400 Subject: [PATCH 2/3] make functions as not nullable #17 --- lib/flutter_statusbar_manager.dart | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/flutter_statusbar_manager.dart b/lib/flutter_statusbar_manager.dart index e9a3e12..d32c1d2 100644 --- a/lib/flutter_statusbar_manager.dart +++ b/lib/flutter_statusbar_manager.dart @@ -9,7 +9,7 @@ class _StatusBarStyle { static const String LIGHT_CONTENT = "light-content"; static const String DARK_CONTENT = "dark-content"; - static String getStyle(StatusBarStyle? style) { + static String getStyle(StatusBarStyle style) { switch (style) { case StatusBarStyle.DEFAULT: return DEFAULT; @@ -17,8 +17,6 @@ class _StatusBarStyle { return DARK_CONTENT; case StatusBarStyle.LIGHT_CONTENT: return LIGHT_CONTENT; - default: - return DEFAULT; } } } @@ -30,7 +28,7 @@ class _StatusBarAnimation { static const String FADE = "fade"; static const String SLIDE = "slide"; - static String getAnimation(StatusBarAnimation? animation) { + static String getAnimation(StatusBarAnimation animation) { switch (animation) { case StatusBarAnimation.NONE: return NONE; @@ -38,8 +36,6 @@ class _StatusBarAnimation { return FADE; case StatusBarAnimation.SLIDE: return SLIDE; - default: - return NONE; } } } @@ -51,7 +47,7 @@ class _NavigationBarStyle { static const String DARK = "light"; static const String LIGHT = "dark"; - static String getStyle(NavigationBarStyle? style) { + static String getStyle(NavigationBarStyle style) { switch (style) { case NavigationBarStyle.DEFAULT: return DEFAULT; @@ -59,8 +55,6 @@ class _NavigationBarStyle { return DARK; case NavigationBarStyle.LIGHT: return LIGHT; - default: - return DEFAULT; } } } From 2c7108a269430aad25b0173328c36f7b9653a795 Mon Sep 17 00:00:00 2001 From: Rafael M Date: Fri, 4 Jun 2021 22:32:28 +0100 Subject: [PATCH 3/3] Fix MissingPluginException for flutter web --- CHANGELOG.md | 8 ++++++++ README.md | 2 ++ example/.flutter-plugins-dependencies | 2 +- example/pubspec.yaml | 6 ++++-- lib/flutter_statusbar_manager.dart | 10 ++++++++++ pubspec.yaml | 5 ++--- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b38cf0b..c98705a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 3.0.1 +* Fix MissingPluginException for flutter web +* Thanks to https://github.com/rafaelmaeuer + +## 3.0.0 +* Added support for null safety +* Thanks to https://github.com/NarHakobyan + ## 2.0.0 * Fix android X * Fix iOS Dark mode styles diff --git a/README.md b/README.md index c063a2e..c1fae7b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # flutter_statusbar_manager +Now compatible with flutter web thanks to https://github.com/rafaelmaeuer +Now with support for null safety thanks to https://github.com/NarHakobyan Now compatible with AndroidX thanks to https://github.com/lorenzOliveto Flutter Statusbar Manager, lets you control the status bar color, style (theme), visibility, and translucent properties across iOS and Android. With some added bonus for Android to control the Navigation Bar. diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 4cbcfc1..567717a 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_statusbar_manager","path":"/Users/mendieta/Projects/flutter_statusbar_manager/","dependencies":[]}],"android":[{"name":"flutter_statusbar_manager","path":"/Users/mendieta/Projects/flutter_statusbar_manager/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_statusbar_manager","dependencies":[]}],"date_created":"2020-08-27 12:17:36.551472","version":"1.20.2"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_statusbar_manager","path":"/Users/rafael/Development/Public/flutter/flutter_statusbar_manager/","dependencies":[]}],"android":[{"name":"flutter_statusbar_manager","path":"/Users/rafael/Development/Public/flutter/flutter_statusbar_manager/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_statusbar_manager","dependencies":[]}],"date_created":"2021-06-04 22:29:15.118836","version":"2.2.1"} \ No newline at end of file diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c172632..950958a 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,13 +1,16 @@ name: flutter_statusbar_manager_example description: Demonstrates how to use the flutter_statusbar_manager plugin. +environment: + sdk: ">=2.12.0 <3.0.0" + dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.3 + cupertino_icons: ^1.0.3 dev_dependencies: flutter_test: @@ -21,7 +24,6 @@ dev_dependencies: # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. diff --git a/lib/flutter_statusbar_manager.dart b/lib/flutter_statusbar_manager.dart index d32c1d2..fc314b7 100644 --- a/lib/flutter_statusbar_manager.dart +++ b/lib/flutter_statusbar_manager.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter/foundation.dart' show kIsWeb; enum StatusBarStyle { DEFAULT, LIGHT_CONTENT, DARK_CONTENT } @@ -64,17 +65,20 @@ class FlutterStatusbarManager { const MethodChannel('flutter_statusbar_manager'); static Future setColor(Color color, {bool animated = false}) async { + if (kIsWeb) return false; return await _channel .invokeMethod("setColor", {'color': color.value, 'animated': animated}); } static Future setTranslucent(bool translucent) async { + if (kIsWeb) return false; return await _channel .invokeMethod("setTranslucent", {'translucent': translucent}); } static Future setHidden(bool hidden, {StatusBarAnimation animation = StatusBarAnimation.NONE}) async { + if (kIsWeb) return false; return await _channel.invokeMethod("setHidden", { 'hidden': hidden, 'animation': _StatusBarAnimation.getAnimation(animation) @@ -82,31 +86,37 @@ class FlutterStatusbarManager { } static Future setStyle(StatusBarStyle style) async { + if (kIsWeb) return false; return await _channel .invokeMethod("setStyle", {'style': _StatusBarStyle.getStyle(style)}); } static Future setNetworkActivityIndicatorVisible(bool visible) async { + if (kIsWeb) return false; return await _channel.invokeMethod( "setNetworkActivityIndicatorVisible", {'visible': visible}); } static Future setNavigationBarColor(Color color, {bool animated = false}) async { + if (kIsWeb) return false; return await _channel.invokeMethod( "setNavigationBarColor", {'color': color.value, 'animated': animated}); } static Future setNavigationBarStyle(NavigationBarStyle style) async { + if (kIsWeb) return false; return await _channel.invokeMethod("setNavigationBarStyle", {'style': _NavigationBarStyle.getStyle(style)}); } static Future get getHeight async { + if (kIsWeb) return 0.0; return await _channel.invokeMethod("getHeight"); } static setFullscreen(bool value) { + if (kIsWeb) return; if (value) { SystemChrome.setEnabledSystemUIOverlays([]); } else { diff --git a/pubspec.yaml b/pubspec.yaml index 4868835..3ebeed1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_statusbar_manager description: Flutter Statusbar Manager, lets you control the status bar color, style (theme), visibility, and translucent properties across iOS and Android. -version: 2.0.0 +version: 3.0.1 homepage: https://github.com/FooStudio/flutter_statusbar_manager dependencies: @@ -8,8 +8,7 @@ dependencies: sdk: flutter environment: - sdk: '>=2.12.0 <3.0.0' - flutter: ">=1.12.0 <2.0.0" + sdk: ">=2.12.0 <3.0.0" dev_dependencies: flutter_test: