Skip to content

Commit ade86c9

Browse files
authored
[connectivity] Add connectivity_tizen package (#29)
1 parent 64e8d64 commit ade86c9

File tree

22 files changed

+623
-0
lines changed

22 files changed

+623
-0
lines changed

packages/connectivity/.gitignore

Lines changed: 7 additions & 0 deletions
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/

packages/connectivity/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
* Initial release

packages/connectivity/LICENSE

Lines changed: 26 additions & 0 deletions
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) 2017 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/connectivity/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# connectivity_tizen
2+
3+
The Tizen implementation of [`connectivity`](https://github.com/flutter/plugins/tree/master/packages/connectivity).
4+
5+
## Usage
6+
7+
This package is not an _endorsed_ implementation of `connectivity`. Therefore, you have to include `connectivity_tizen` alongside `connectivity` as dependencies in your `pubspec.yaml` file.
8+
9+
```yaml
10+
dependencies:
11+
connectivity: ^2.0.2
12+
connectivity_tizen: ^1.0.0
13+
```
14+
Then you can import `connectivity` in your Dart code:
15+
16+
```dart
17+
import 'package:connectivity/connectivity.dart';
18+
```
19+
20+
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/connectivity/connectivity#usage.
21+
22+
## Supported devices
23+
24+
This plugin is supported on these types of devices:
25+
26+
- Galaxy Watch (running Tizen 4.0 or later)
27+
28+
## Required privileges
29+
30+
To get connectivity information using this plugin, add below lines under the `<manifest>` section in your `tizen-manifest.xml` file,
31+
32+
```xml
33+
<privileges>
34+
<privilege>http://tizen.org/privilege/network.get</privilege>
35+
</privileges>
36+
```
Lines changed: 41 additions & 0 deletions
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
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# connectiviy example
2+
3+
Demonstrates how to use the connectiviy 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).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2019 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 'package:integration_test/integration_test.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:connectivity/connectivity.dart';
8+
9+
void main() {
10+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
11+
12+
group('Connectivity test driver', () {
13+
Connectivity _connectivity;
14+
15+
setUpAll(() async {
16+
_connectivity = Connectivity();
17+
});
18+
19+
testWidgets('test connectivity result', (WidgetTester tester) async {
20+
final ConnectivityResult result = await _connectivity.checkConnectivity();
21+
expect(result, isNotNull);
22+
});
23+
});
24+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2017 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+
import 'package:flutter/foundation.dart';
12+
import 'package:flutter/material.dart';
13+
import 'package:flutter/services.dart';
14+
15+
// Sets a platform override for desktop to avoid exceptions. See
16+
// https://flutter.dev/desktop#target-platform-override for more info.
17+
void _enablePlatformOverrideForDesktop() {
18+
if (!kIsWeb && (Platform.isWindows || Platform.isLinux)) {
19+
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
20+
}
21+
}
22+
23+
void main() {
24+
_enablePlatformOverrideForDesktop();
25+
runApp(MyApp());
26+
}
27+
28+
class MyApp extends StatelessWidget {
29+
// This widget is the root of your application.
30+
@override
31+
Widget build(BuildContext context) {
32+
return MaterialApp(
33+
title: 'Flutter Demo',
34+
theme: ThemeData(
35+
primarySwatch: Colors.blue,
36+
),
37+
home: MyHomePage(title: 'Flutter Demo Home Page'),
38+
);
39+
}
40+
}
41+
42+
class MyHomePage extends StatefulWidget {
43+
MyHomePage({Key key, this.title}) : super(key: key);
44+
45+
final String title;
46+
47+
@override
48+
_MyHomePageState createState() => _MyHomePageState();
49+
}
50+
51+
class _MyHomePageState extends State<MyHomePage> {
52+
String _connectionStatus = 'Unknown';
53+
final Connectivity _connectivity = Connectivity();
54+
StreamSubscription<ConnectivityResult> _connectivitySubscription;
55+
56+
@override
57+
void initState() {
58+
super.initState();
59+
initConnectivity();
60+
_connectivitySubscription =
61+
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
62+
}
63+
64+
@override
65+
void dispose() {
66+
_connectivitySubscription.cancel();
67+
super.dispose();
68+
}
69+
70+
// Platform messages are asynchronous, so we initialize in an async method.
71+
Future<void> initConnectivity() async {
72+
ConnectivityResult result;
73+
// Platform messages may fail, so we use a try/catch PlatformException.
74+
try {
75+
result = await _connectivity.checkConnectivity();
76+
} on PlatformException catch (e) {
77+
print(e.toString());
78+
}
79+
80+
// If the widget was removed from the tree while the asynchronous platform
81+
// message was in flight, we want to discard the reply rather than calling
82+
// setState to update our non-existent appearance.
83+
if (!mounted) {
84+
return Future.value(null);
85+
}
86+
87+
return _updateConnectionStatus(result);
88+
}
89+
90+
@override
91+
Widget build(BuildContext context) {
92+
return Scaffold(
93+
appBar: AppBar(
94+
title: const Text('Connectivity example app'),
95+
),
96+
body: Center(child: Text('Connection Status: $_connectionStatus')),
97+
);
98+
}
99+
100+
Future<void> _updateConnectionStatus(ConnectivityResult result) async {
101+
switch (result) {
102+
case ConnectivityResult.wifi:
103+
case ConnectivityResult.mobile:
104+
case ConnectivityResult.none:
105+
setState(() => _connectionStatus = result.toString());
106+
break;
107+
default:
108+
setState(() => _connectionStatus = 'Failed to get connectivity.');
109+
break;
110+
}
111+
}
112+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: connectivity_example
2+
description: Demonstrates how to use the connectivity plugin.
3+
publish_to: 'none'
4+
5+
dependencies:
6+
flutter:
7+
sdk: flutter
8+
connectivity: ^2.0.2
9+
connectivity_tizen:
10+
path: ../
11+
12+
dev_dependencies:
13+
flutter_driver:
14+
sdk: flutter
15+
test: any
16+
pedantic: ^1.8.0
17+
integration_test: ^1.0.1
18+
integration_test_tizen:
19+
path: ../../integration_test/
20+
21+
flutter:
22+
uses-material-design: true
Lines changed: 3 additions & 0 deletions
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();

0 commit comments

Comments
 (0)