Skip to content

Commit 6342185

Browse files
bwikbsswift-kim
andauthored
[wifi_info_flutter] Add wifi_info_flutter_tizen package (#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]>
1 parent c40bf67 commit 6342185

23 files changed

+659
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
2323
| [**share_tizen**](packages/share) | [share](https://github.com/flutter/plugins/tree/master/packages/share) (1st-party) | [![pub package](https://img.shields.io/pub/v/share_tizen.svg)](https://pub.dev/packages/share_tizen) | No |
2424
| [**shared_preferences_tizen**](packages/path_provider) | [shared_preferences](https://github.com/flutter/plugins/tree/master/packages/shared_preferences) (1st-party) | [![pub package](https://img.shields.io/pub/v/shared_preferences_tizen.svg)](https://pub.dev/packages/shared_preferences_tizen) | No |
2525
| [**url_launcher_tizen**](packages/url_launcher) | [url_launcher](https://github.com/flutter/plugins/tree/master/packages/url_launcher) (1st-party) | [![pub package](https://img.shields.io/pub/v/url_launcher_tizen.svg)](https://pub.dev/packages/url_launcher_tizen) | No |
26+
| [**wifi_info_flutter_tizen**](packages/wifi_info_flutter) | [wifi_info_flutter](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter) (1st-party) | [![pub package](https://img.shields.io/pub/v/wifi_info_flutter_tizen.svg)](https://pub.dev/packages/wifi_info_flutter_tizen) | No |
2627

2728
## Device limitations
2829

@@ -39,3 +40,4 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
3940
| [**share_tizen**](packages/share) | ⚠️ | ⚠️ ||| No SMS or e-mail app |
4041
| [**shared_preferences_tizen**](packages/path_provider) | ✔️ | ✔️ | ✔️ | ✔️ |
4142
| [**url_launcher_tizen**](packages/url_launcher) | ✔️ || ✔️ || No browser app |
43+
| [**wifi_info_flutter_tizen**](packages/wifi_info_flutter) | ✔️ || ✔️ ||

packages/wifi_info_flutter/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
.dart_tool/
3+
4+
.packages
5+
.pub/
6+
7+
build/
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Initial release

packages/wifi_info_flutter/LICENSE

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
Copyright (c) 2020 The Chromium Authors. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the names of the copyright holders nor the names of the
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/wifi_info_flutter/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# wifi_info_flutter_tizen
2+
3+
The Tizen implementation of [`wifi_info_flutter`](https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter).
4+
5+
## Usage
6+
7+
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.
8+
9+
```yaml
10+
dependencies:
11+
wifi_info_flutter: ^1.0.1
12+
wifi_info_flutter_tizen: ^1.0.0
13+
```
14+
15+
Then you can import `wifi_info_flutter` in your Dart code:
16+
17+
```dart
18+
import 'package:wifi_info_flutter/wifi_info_flutter.dart';
19+
```
20+
21+
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/wifi_info_flutter/wifi_info_flutter#usage.
22+
23+
## Required privileges
24+
25+
To get network information using this plugin, add below lines under the `<manifest>` section in your `tizen-manifest.xml` file,
26+
27+
```xml
28+
<privileges>
29+
<privilege>http://tizen.org/privilege/network.get</privilege>
30+
</privileges>
31+
```
32+
33+
For details, see [Security and API Privileges](https://docs.tizen.org/application/dotnet/tutorials/sec-privileges).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# wifi_info_flutter_example
2+
3+
Demonstrates how to use the wifi_info_flutter_tizen plugin.
4+
5+
## Getting Started
6+
7+
To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:io';
6+
import 'package:integration_test/integration_test.dart';
7+
import 'package:flutter_test/flutter_test.dart';
8+
import 'package:wifi_info_flutter/wifi_info_flutter.dart';
9+
10+
void main() {
11+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
12+
13+
group('$WifiInfo test driver', () {
14+
WifiInfo _wifiInfo;
15+
16+
setUpAll(() async {
17+
_wifiInfo = WifiInfo();
18+
});
19+
20+
testWidgets('test location methods, iOS only', (WidgetTester tester) async {
21+
expect(
22+
(await _wifiInfo.getLocationServiceAuthorization()),
23+
LocationAuthorizationStatus.notDetermined,
24+
);
25+
}, skip: !Platform.isIOS);
26+
});
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// Copyright 2020 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:async';
8+
import 'dart:io';
9+
10+
import 'package:connectivity/connectivity.dart'
11+
show Connectivity, ConnectivityResult;
12+
import 'package:flutter/foundation.dart';
13+
import 'package:flutter/material.dart';
14+
import 'package:flutter/services.dart';
15+
import 'package:wifi_info_flutter/wifi_info_flutter.dart';
16+
17+
// Sets a platform override for desktop to avoid exceptions. See
18+
// https://flutter.dev/desktop#target-platform-override for more info.
19+
void _enablePlatformOverrideForDesktop() {
20+
if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
21+
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
22+
}
23+
}
24+
25+
void main() {
26+
_enablePlatformOverrideForDesktop();
27+
runApp(MyApp());
28+
}
29+
30+
class MyApp extends StatelessWidget {
31+
// This widget is the root of your application.
32+
@override
33+
Widget build(BuildContext context) {
34+
return MaterialApp(
35+
title: 'Flutter Demo',
36+
theme: ThemeData(
37+
primarySwatch: Colors.blue,
38+
),
39+
home: MyHomePage(title: 'Flutter Demo Home Page'),
40+
);
41+
}
42+
}
43+
44+
class MyHomePage extends StatefulWidget {
45+
MyHomePage({Key key, this.title}) : super(key: key);
46+
47+
final String title;
48+
49+
@override
50+
_MyHomePageState createState() => _MyHomePageState();
51+
}
52+
53+
class _MyHomePageState extends State<MyHomePage> {
54+
String _connectionStatus = 'Unknown';
55+
final Connectivity _connectivity = Connectivity();
56+
final WifiInfo _wifiInfo = WifiInfo();
57+
StreamSubscription<ConnectivityResult> _connectivitySubscription;
58+
59+
@override
60+
void initState() {
61+
super.initState();
62+
initConnectivity();
63+
_connectivitySubscription =
64+
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
65+
}
66+
67+
@override
68+
void dispose() {
69+
_connectivitySubscription.cancel();
70+
super.dispose();
71+
}
72+
73+
// Platform messages are asynchronous, so we initialize in an async method.
74+
Future<void> initConnectivity() async {
75+
ConnectivityResult result;
76+
// Platform messages may fail, so we use a try/catch PlatformException.
77+
try {
78+
result = await _connectivity.checkConnectivity();
79+
} on PlatformException catch (e) {
80+
print(e.toString());
81+
}
82+
83+
// If the widget was removed from the tree while the asynchronous platform
84+
// message was in flight, we want to discard the reply rather than calling
85+
// setState to update our non-existent appearance.
86+
if (!mounted) {
87+
return Future.value(null);
88+
}
89+
90+
return _updateConnectionStatus(result);
91+
}
92+
93+
@override
94+
Widget build(BuildContext context) {
95+
return Scaffold(
96+
appBar: AppBar(
97+
title: const Text('Connectivity example app'),
98+
),
99+
body: Center(child: Text('Connection Status: $_connectionStatus')),
100+
);
101+
}
102+
103+
Future<void> _updateConnectionStatus(ConnectivityResult result) async {
104+
switch (result) {
105+
case ConnectivityResult.wifi:
106+
String wifiName, wifiBSSID, wifiIP;
107+
108+
try {
109+
if (!kIsWeb && Platform.isIOS) {
110+
LocationAuthorizationStatus status =
111+
await _wifiInfo.getLocationServiceAuthorization();
112+
if (status == LocationAuthorizationStatus.notDetermined) {
113+
status = await _wifiInfo.requestLocationServiceAuthorization();
114+
}
115+
if (status == LocationAuthorizationStatus.authorizedAlways ||
116+
status == LocationAuthorizationStatus.authorizedWhenInUse) {
117+
wifiName = await _wifiInfo.getWifiName();
118+
} else {
119+
wifiName = await _wifiInfo.getWifiName();
120+
}
121+
} else {
122+
wifiName = await _wifiInfo.getWifiName();
123+
}
124+
} on PlatformException catch (e) {
125+
print(e.toString());
126+
wifiName = "Failed to get Wifi Name";
127+
}
128+
129+
try {
130+
if (!kIsWeb && Platform.isIOS) {
131+
LocationAuthorizationStatus status =
132+
await _wifiInfo.getLocationServiceAuthorization();
133+
if (status == LocationAuthorizationStatus.notDetermined) {
134+
status = await _wifiInfo.requestLocationServiceAuthorization();
135+
}
136+
if (status == LocationAuthorizationStatus.authorizedAlways ||
137+
status == LocationAuthorizationStatus.authorizedWhenInUse) {
138+
wifiBSSID = await _wifiInfo.getWifiBSSID();
139+
} else {
140+
wifiBSSID = await _wifiInfo.getWifiBSSID();
141+
}
142+
} else {
143+
wifiBSSID = await _wifiInfo.getWifiBSSID();
144+
}
145+
} on PlatformException catch (e) {
146+
print(e.toString());
147+
wifiBSSID = "Failed to get Wifi BSSID";
148+
}
149+
150+
try {
151+
wifiIP = await _wifiInfo.getWifiIP();
152+
} on PlatformException catch (e) {
153+
print(e.toString());
154+
wifiIP = "Failed to get Wifi IP";
155+
}
156+
157+
setState(() {
158+
_connectionStatus = '$result\n'
159+
'Wifi Name: $wifiName\n'
160+
'Wifi BSSID: $wifiBSSID\n'
161+
'Wifi IP: $wifiIP\n';
162+
});
163+
break;
164+
case ConnectivityResult.mobile:
165+
case ConnectivityResult.none:
166+
setState(() => _connectionStatus = result.toString());
167+
break;
168+
default:
169+
setState(() => _connectionStatus = 'Failed to get connectivity.');
170+
break;
171+
}
172+
}
173+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: wifi_info_flutter_tizen_example
2+
description: Demonstrates how to use the wifi_info_flutter_tizen plugin.
3+
publish_to: 'none'
4+
5+
dependencies:
6+
connectivity: ^2.0.2
7+
connectivity_tizen:
8+
path: ../../connectivity/
9+
cupertino_icons: ^1.0.0
10+
flutter:
11+
sdk: flutter
12+
integration_test: ^1.0.1
13+
integration_test_tizen:
14+
path: ../../integration_test/
15+
wifi_info_flutter: ^1.0.1
16+
wifi_info_flutter_tizen:
17+
path: ../
18+
19+
dev_dependencies:
20+
flutter_test:
21+
sdk: flutter
22+
23+
flutter:
24+
uses-material-design: true
25+
26+
environment:
27+
sdk: ">=2.7.0 <3.0.0"
28+
flutter: ">=1.20.0 <2.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import 'package:integration_test/integration_test_driver.dart';
2+
3+
Future<void> main() => integrationDriver();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
flutter/
2+
.vs/
3+
*.user
4+
bin/
5+
obj/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Tizen.Flutter.Embedding;
2+
3+
namespace Runner
4+
{
5+
public class App : FlutterApplication
6+
{
7+
protected override void OnCreate()
8+
{
9+
base.OnCreate();
10+
11+
GeneratedPluginRegistrant.RegisterPlugins(this);
12+
}
13+
14+
static void Main(string[] args)
15+
{
16+
var app = new App();
17+
app.Run(args);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)