forked from flutter-tizen/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wifi_info_flutter] Add wifi_info_flutter_tizen package (flutter-tize…
…n#34) * [wifi_info_flutter] Add wifi_info_flutter_tizen package * Update example app * Update pubspec and etc. * Apply coding rules * Update README Co-authored-by: Swift Kim <[email protected]>
- Loading branch information
Showing
23 changed files
with
659 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
.dart_tool/ | ||
|
||
.packages | ||
.pub/ | ||
|
||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 1.0.0 | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||
Copyright (c) 2020 The Chromium Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the names of the copyright holders nor the names of the | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# wifi_info_flutter_tizen | ||
|
||
The Tizen implementation of [`wifi_info_flutter`](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter). | ||
|
||
## Usage | ||
|
||
This package is not an _endorsed_ implementation of `wifi_info_flutter`. Therefore, you have to include `wifi_info_flutter_tizen` alongside `wifi_info_flutter` as dependencies in your `pubspec.yaml` file. | ||
|
||
```yaml | ||
dependencies: | ||
wifi_info_flutter: ^1.0.1 | ||
wifi_info_flutter_tizen: ^1.0.0 | ||
``` | ||
Then you can import `wifi_info_flutter` in your Dart code: | ||
|
||
```dart | ||
import 'package:wifi_info_flutter/wifi_info_flutter.dart'; | ||
``` | ||
|
||
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter#usage. | ||
|
||
## Required privileges | ||
|
||
To get network information using this plugin, add below lines under the `<manifest>` section in your `tizen-manifest.xml` file, | ||
|
||
```xml | ||
<privileges> | ||
<privilege>http://tizen.org/privilege/network.get</privilege> | ||
</privileges> | ||
``` | ||
|
||
For details, see [Security and API Privileges](https://docs.tizen.org/application/dotnet/tutorials/sec-privileges). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# wifi_info_flutter_example | ||
|
||
Demonstrates how to use the wifi_info_flutter_tizen plugin. | ||
|
||
## Getting Started | ||
|
||
To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen). |
27 changes: 27 additions & 0 deletions
27
packages/wifi_info_flutter/example/integration_test/wifi_info_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:wifi_info_flutter/wifi_info_flutter.dart'; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
group('$WifiInfo test driver', () { | ||
WifiInfo _wifiInfo; | ||
|
||
setUpAll(() async { | ||
_wifiInfo = WifiInfo(); | ||
}); | ||
|
||
testWidgets('test location methods, iOS only', (WidgetTester tester) async { | ||
expect( | ||
(await _wifiInfo.getLocationServiceAuthorization()), | ||
LocationAuthorizationStatus.notDetermined, | ||
); | ||
}, skip: !Platform.isIOS); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// ignore_for_file: public_member_api_docs | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:connectivity/connectivity.dart' | ||
show Connectivity, ConnectivityResult; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:wifi_info_flutter/wifi_info_flutter.dart'; | ||
|
||
// Sets a platform override for desktop to avoid exceptions. See | ||
// https://flutter.dev/desktop#target-platform-override for more info. | ||
void _enablePlatformOverrideForDesktop() { | ||
if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) { | ||
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia; | ||
} | ||
} | ||
|
||
void main() { | ||
_enablePlatformOverrideForDesktop(); | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
// This widget is the root of your application. | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Demo', | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
), | ||
home: MyHomePage(title: 'Flutter Demo Home Page'), | ||
); | ||
} | ||
} | ||
|
||
class MyHomePage extends StatefulWidget { | ||
MyHomePage({Key key, this.title}) : super(key: key); | ||
|
||
final String title; | ||
|
||
@override | ||
_MyHomePageState createState() => _MyHomePageState(); | ||
} | ||
|
||
class _MyHomePageState extends State<MyHomePage> { | ||
String _connectionStatus = 'Unknown'; | ||
final Connectivity _connectivity = Connectivity(); | ||
final WifiInfo _wifiInfo = WifiInfo(); | ||
StreamSubscription<ConnectivityResult> _connectivitySubscription; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
initConnectivity(); | ||
_connectivitySubscription = | ||
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_connectivitySubscription.cancel(); | ||
super.dispose(); | ||
} | ||
|
||
// Platform messages are asynchronous, so we initialize in an async method. | ||
Future<void> initConnectivity() async { | ||
ConnectivityResult result; | ||
// Platform messages may fail, so we use a try/catch PlatformException. | ||
try { | ||
result = await _connectivity.checkConnectivity(); | ||
} on PlatformException catch (e) { | ||
print(e.toString()); | ||
} | ||
|
||
// If the widget was removed from the tree while the asynchronous platform | ||
// message was in flight, we want to discard the reply rather than calling | ||
// setState to update our non-existent appearance. | ||
if (!mounted) { | ||
return Future.value(null); | ||
} | ||
|
||
return _updateConnectionStatus(result); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Connectivity example app'), | ||
), | ||
body: Center(child: Text('Connection Status: $_connectionStatus')), | ||
); | ||
} | ||
|
||
Future<void> _updateConnectionStatus(ConnectivityResult result) async { | ||
switch (result) { | ||
case ConnectivityResult.wifi: | ||
String wifiName, wifiBSSID, wifiIP; | ||
|
||
try { | ||
if (!kIsWeb && Platform.isIOS) { | ||
LocationAuthorizationStatus status = | ||
await _wifiInfo.getLocationServiceAuthorization(); | ||
if (status == LocationAuthorizationStatus.notDetermined) { | ||
status = await _wifiInfo.requestLocationServiceAuthorization(); | ||
} | ||
if (status == LocationAuthorizationStatus.authorizedAlways || | ||
status == LocationAuthorizationStatus.authorizedWhenInUse) { | ||
wifiName = await _wifiInfo.getWifiName(); | ||
} else { | ||
wifiName = await _wifiInfo.getWifiName(); | ||
} | ||
} else { | ||
wifiName = await _wifiInfo.getWifiName(); | ||
} | ||
} on PlatformException catch (e) { | ||
print(e.toString()); | ||
wifiName = "Failed to get Wifi Name"; | ||
} | ||
|
||
try { | ||
if (!kIsWeb && Platform.isIOS) { | ||
LocationAuthorizationStatus status = | ||
await _wifiInfo.getLocationServiceAuthorization(); | ||
if (status == LocationAuthorizationStatus.notDetermined) { | ||
status = await _wifiInfo.requestLocationServiceAuthorization(); | ||
} | ||
if (status == LocationAuthorizationStatus.authorizedAlways || | ||
status == LocationAuthorizationStatus.authorizedWhenInUse) { | ||
wifiBSSID = await _wifiInfo.getWifiBSSID(); | ||
} else { | ||
wifiBSSID = await _wifiInfo.getWifiBSSID(); | ||
} | ||
} else { | ||
wifiBSSID = await _wifiInfo.getWifiBSSID(); | ||
} | ||
} on PlatformException catch (e) { | ||
print(e.toString()); | ||
wifiBSSID = "Failed to get Wifi BSSID"; | ||
} | ||
|
||
try { | ||
wifiIP = await _wifiInfo.getWifiIP(); | ||
} on PlatformException catch (e) { | ||
print(e.toString()); | ||
wifiIP = "Failed to get Wifi IP"; | ||
} | ||
|
||
setState(() { | ||
_connectionStatus = '$result\n' | ||
'Wifi Name: $wifiName\n' | ||
'Wifi BSSID: $wifiBSSID\n' | ||
'Wifi IP: $wifiIP\n'; | ||
}); | ||
break; | ||
case ConnectivityResult.mobile: | ||
case ConnectivityResult.none: | ||
setState(() => _connectionStatus = result.toString()); | ||
break; | ||
default: | ||
setState(() => _connectionStatus = 'Failed to get connectivity.'); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: wifi_info_flutter_tizen_example | ||
description: Demonstrates how to use the wifi_info_flutter_tizen plugin. | ||
publish_to: 'none' | ||
|
||
dependencies: | ||
connectivity: ^2.0.2 | ||
connectivity_tizen: | ||
path: ../../connectivity/ | ||
cupertino_icons: ^1.0.0 | ||
flutter: | ||
sdk: flutter | ||
integration_test: ^1.0.1 | ||
integration_test_tizen: | ||
path: ../../integration_test/ | ||
wifi_info_flutter: ^1.0.1 | ||
wifi_info_flutter_tizen: | ||
path: ../ | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
|
||
flutter: | ||
uses-material-design: true | ||
|
||
environment: | ||
sdk: ">=2.7.0 <3.0.0" | ||
flutter: ">=1.20.0 <2.0.0" |
3 changes: 3 additions & 0 deletions
3
packages/wifi_info_flutter/example/test_driver/integration_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import 'package:integration_test/integration_test_driver.dart'; | ||
|
||
Future<void> main() => integrationDriver(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
flutter/ | ||
.vs/ | ||
*.user | ||
bin/ | ||
obj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Tizen.Flutter.Embedding; | ||
|
||
namespace Runner | ||
{ | ||
public class App : FlutterApplication | ||
{ | ||
protected override void OnCreate() | ||
{ | ||
base.OnCreate(); | ||
|
||
GeneratedPluginRegistrant.RegisterPlugins(this); | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
var app = new App(); | ||
app.Run(args); | ||
} | ||
} | ||
} |
Oops, something went wrong.