From c08196edf53f487b63019be901f98b2809fc6289 Mon Sep 17 00:00:00 2001 From: Muhammed-Ayad Date: Mon, 10 Apr 2023 17:21:25 +0200 Subject: [PATCH 1/3] Refactored and null-safe version of the code --- lib/screen.dart | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/screen.dart b/lib/screen.dart index 4dbc0d1..45d8189 100644 --- a/lib/screen.dart +++ b/lib/screen.dart @@ -1,12 +1,18 @@ -import 'dart:async'; - import 'package:flutter/services.dart'; class Screen { - static const MethodChannel _channel = const MethodChannel('github.com/clovisnicolas/flutter_screen'); + static const MethodChannel _channel = + const MethodChannel('github.com/clovisnicolas/flutter_screen'); + + static Future get brightness async => + (await _channel.invokeMethod('brightness')) as double?; + + static Future setBrightness(double brightness) => + _channel.invokeMethod('setBrightness', {"brightness": brightness}); + + static Future get isKeptOn async => + (await _channel.invokeMethod('isKeptOn')) as bool?; - static Future get brightness async => (await _channel.invokeMethod('brightness')) as double; - static Future setBrightness(double brightness) =>_channel.invokeMethod('setBrightness',{"brightness" : brightness}); - static Future get isKeptOn async => (await _channel.invokeMethod('isKeptOn')) as bool; - static Future keepOn(bool on) => _channel.invokeMethod('keepOn', {"on" : on}); -} + static Future keepOn(bool on) => + _channel.invokeMethod('keepOn', {"on": on}); +} \ No newline at end of file From cde52cf30e6655be4778f63da4b6d6489b8c6b19 Mon Sep 17 00:00:00 2001 From: Muhammed-Ayad Date: Mon, 10 Apr 2023 17:21:51 +0200 Subject: [PATCH 2/3] edit main file --- .dart_tool/package_config.json | 62 +++++++++++++++++++++++++++++ example/lib/main.dart | 72 ++++++++++++++++++++-------------- pubspec.yaml | 2 +- 3 files changed, 105 insertions(+), 31 deletions(-) create mode 100644 .dart_tool/package_config.json diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json new file mode 100644 index 0000000..549e298 --- /dev/null +++ b/.dart_tool/package_config.json @@ -0,0 +1,62 @@ +{ + "configVersion": 2, + "packages": [ + { + "name": "characters", + "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/characters-1.2.1", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "collection", + "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/collection-1.17.0", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "flutter", + "rootUri": "file:///home/ayad/snap/flutter/common/flutter/packages/flutter", + "packageUri": "lib/", + "languageVersion": "2.17" + }, + { + "name": "js", + "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/js-0.6.5", + "packageUri": "lib/", + "languageVersion": "2.16" + }, + { + "name": "material_color_utilities", + "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/material_color_utilities-0.2.0", + "packageUri": "lib/", + "languageVersion": "2.13" + }, + { + "name": "meta", + "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/meta-1.8.0", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "sky_engine", + "rootUri": "file:///home/ayad/snap/flutter/common/flutter/bin/cache/pkg/sky_engine", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "vector_math", + "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/vector_math-2.1.4", + "packageUri": "lib/", + "languageVersion": "2.14" + }, + { + "name": "screen", + "rootUri": "../", + "packageUri": "lib/", + "languageVersion": "2.12" + } + ], + "generated": "2023-04-10T15:12:13.880404Z", + "generator": "pub", + "generatorVersion": "2.19.3" +} diff --git a/example/lib/main.dart b/example/lib/main.dart index bf59225..5cc6a86 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:screen/screen.dart'; -void main() => runApp(new MyApp()); +void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override - _MyAppState createState() => new _MyAppState(); + _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { @@ -13,45 +13,57 @@ class _MyAppState extends State { double _brightness = 1.0; @override - initState() { + void initState() { super.initState(); initPlatformState(); } - initPlatformState() async { - bool keptOn = await Screen.isKeptOn; - double brightness = await Screen.brightness; - setState((){ - _isKeptOn = keptOn; - _brightness = brightness; + Future initPlatformState() async { + bool? keptOn = await Screen.isKeptOn; + double? brightness = await Screen.brightness; + setState(() { + _isKeptOn = keptOn ?? false; + _brightness = brightness ?? 1.0; }); } @override Widget build(BuildContext context) { - return new MaterialApp( - home: new Scaffold( - appBar: new AppBar(title: new Text('Screen plugin example')), - body: new Center( - child: new Column( + return MaterialApp( + home: Scaffold( + appBar: AppBar(title: Text('Screen plugin example')), + body: Center( + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, children: [ - new Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - new Text("Screen is kept on ? "), - new Checkbox(value: _isKeptOn, onChanged: (bool b){ + Text("Screen is kept on ? "), + Checkbox( + value: _isKeptOn, + onChanged: (bool? b) { + if (b != null) { Screen.keepOn(b); - setState((){_isKeptOn = b; }); - }) - ] - ), - new Text("Brightness :"), - new Slider(value : _brightness, onChanged : (double b){ - setState((){_brightness = b;}); - Screen.setBrightness(b); - }) - ] - ) + setState(() { + _isKeptOn = b; + }); + } + }, + ) + ], + ), + Text("Brightness :"), + Slider( + value: _brightness, + onChanged: (double b) { + setState(() { + _brightness = b; + }); + Screen.setBrightness(b); + }, + ) + ], + ), ), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index c3531d0..eec30e5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ author: Clovis Nicolas homepage: https://github.com/clovisnicolas/flutter_screen environment: - sdk: '>=2.0.0 <3.0.0' + sdk: ">=2.12.0 <3.0.0" dependencies: flutter: From d956683ef14c42b3aaff6c9c642698f0877fb25e Mon Sep 17 00:00:00 2001 From: Mohamed Ayad <57087983+Muhammed-Ayad@users.noreply.github.com> Date: Mon, 10 Apr 2023 17:27:38 +0200 Subject: [PATCH 3/3] Delete package_config.json --- .dart_tool/package_config.json | 62 ---------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 .dart_tool/package_config.json diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json deleted file mode 100644 index 549e298..0000000 --- a/.dart_tool/package_config.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "characters", - "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/characters-1.2.1", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "collection", - "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/collection-1.17.0", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "flutter", - "rootUri": "file:///home/ayad/snap/flutter/common/flutter/packages/flutter", - "packageUri": "lib/", - "languageVersion": "2.17" - }, - { - "name": "js", - "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/js-0.6.5", - "packageUri": "lib/", - "languageVersion": "2.16" - }, - { - "name": "material_color_utilities", - "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/material_color_utilities-0.2.0", - "packageUri": "lib/", - "languageVersion": "2.13" - }, - { - "name": "meta", - "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/meta-1.8.0", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "sky_engine", - "rootUri": "file:///home/ayad/snap/flutter/common/flutter/bin/cache/pkg/sky_engine", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "vector_math", - "rootUri": "file:///home/ayad/.pub-cache/hosted/pub.dev/vector_math-2.1.4", - "packageUri": "lib/", - "languageVersion": "2.14" - }, - { - "name": "screen", - "rootUri": "../", - "packageUri": "lib/", - "languageVersion": "2.12" - } - ], - "generated": "2023-04-10T15:12:13.880404Z", - "generator": "pub", - "generatorVersion": "2.19.3" -}