Skip to content

Commit 9f34501

Browse files
authored
Merge pull request #36 from osociety/dev
Dev -> Main
2 parents cf776f9 + df365b1 commit 9f34501

12 files changed

+245
-89
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 1.0.5
4+
5+
1. scanPortsForSingleDevice and customDiscover supports async mode now.
6+
37
## 1.0.4
48

59
1. Use network_tools v4.0.1 to fix path issue in flutter.

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Features
66

7-
This package will add support for flutter features which is out of the scope of [network_tools](https://github.com/osociety/network_tools) because of platform limitations but network_tools must also be added to pubspec.yml
7+
This package will add support for flutter features which is out of the scope of [network_tools](https://github.com/osociety/network_tools) because of platform limitations.
88

99
## Getting started
1010

@@ -16,8 +16,7 @@ dependencies:
1616
flutter:
1717
sdk: flutter
1818

19-
network_tools_flutter: ^1.0.1
20-
network_tools: ^3.2.4
19+
network_tools_flutter: ^1.0.4
2120
```
2221
2322
Import package in your project
@@ -29,4 +28,4 @@ Use HostScannerFlutter and PortScannerFlutter for your flutter projects. See exa
2928

3029
## Additional information
3130

32-
You can use same methods but need to import from network_tools_flutter.
31+
You can use same APIs but need to import from network_tools_flutter. All APIs from network_tools are automatically imported by network_tools_flutter. So just import network_tools_flutter in your flutter app.

analysis_options.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1+
# Defines a default set of lint rules enforced for
2+
# projects at Google. For details and rationale,
3+
# see https://github.com/dart-lang/pedantic#enabled-lints.
4+
# include: package:pedantic/analysis_options.yaml
5+
6+
# lint analysis
17
include: package:flutter_lints/flutter.yaml
28

3-
# Additional information about this file can be found at
4-
# https://dart.dev/guides/language/analysis-options
9+
10+
analyzer:
11+
errors:
12+
missing_required_param: error
13+
missing_return: error
14+
must_be_immutable: error
15+
exclude:
16+
- "**/*.g.dart"
17+
- "**/*.freezed.dart"
18+
- "**/*.config.dart"
19+
- "**/*.pb.dart"
20+
- "**/*.pbenum.dart"
21+
- "**/*.pbgrpc.dart"
22+
- "**/*.pbjson.dart"
23+
- "**/*.gr.dart"
24+
- "**/*.md"
25+
- "example/**"
26+
27+
linter:
28+
rules:
29+
# Use parameter order as in json response
30+
always_put_required_named_parameters_first: true
31+
32+
avoid_classes_with_only_static_members: false
33+
34+
sort_constructors_first: true
35+
36+
avoid_relative_lib_imports: false

example/lib/main.dart

Lines changed: 34 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:example/pages/pingable_devices.dart';
2+
import 'package:example/pages/port_scanner_page.dart';
13
import 'package:flutter/material.dart';
24
import 'package:network_tools_flutter/network_tools_flutter.dart';
35
import 'package:path_provider/path_provider.dart';
@@ -36,75 +38,48 @@ class MyApp extends StatelessWidget {
3638
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
3739
useMaterial3: true,
3840
),
39-
home: const MyHomePage(title: 'Network Tools Flutter'),
41+
home: const MyHomePage(),
4042
);
4143
}
4244
}
4345

44-
class MyHomePage extends StatefulWidget {
45-
const MyHomePage({super.key, required this.title});
46-
47-
// This widget is the home page of your application. It is stateful, meaning
48-
// that it has a State object (defined below) that contains fields that affect
49-
// how it looks.
50-
51-
// This class is the configuration for the state. It holds the values (in this
52-
// case the title) provided by the parent (in this case the App widget) and
53-
// used by the build method of the State. Fields in a Widget subclass are
54-
// always marked "final".
55-
56-
final String title;
57-
58-
@override
59-
State<MyHomePage> createState() => _MyHomePageState();
60-
}
61-
62-
class _MyHomePageState extends State<MyHomePage> {
63-
List<ActiveHost> activeHosts = [];
64-
65-
@override
66-
void initState() {
67-
super.initState();
68-
NetInterface.localInterface().then((value) {
69-
final netInt = value;
70-
if (netInt != null) {
71-
HostScannerFlutter.getAllPingableDevices(netInt.networkId)
72-
.listen((host) {
73-
setState(() {
74-
activeHosts.add(host);
75-
});
76-
});
77-
}
78-
});
79-
}
46+
class MyHomePage extends StatelessWidget {
47+
const MyHomePage({super.key});
8048

8149
@override
8250
Widget build(BuildContext context) {
83-
// This method is rerun every time setState is called, for instance as done
84-
// by the _incrementCounter method above.
85-
//
86-
// The Flutter framework has been optimized to make rerunning build methods
87-
// fast, so that you can just rebuild anything that needs updating rather
88-
// than having to individually change instances of widgets.
8951
return Scaffold(
9052
appBar: AppBar(
91-
// TRY THIS: Try changing the color here to a specific color (to
92-
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
93-
// change color while the other colors stay the same.
94-
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
95-
// Here we take the value from the MyHomePage object that was created by
96-
// the App.build method, and use it to set our appbar title.
97-
title: Text(widget.title),
53+
title: const Text('Home'),
9854
),
99-
body: Center(
100-
child: ListView.builder(
101-
itemCount: activeHosts.length,
102-
itemBuilder: (context, index) {
103-
return ListTile(
104-
title: Text(activeHosts[index].address),
105-
);
106-
},
107-
),
55+
body: Column(
56+
crossAxisAlignment: CrossAxisAlignment.center,
57+
mainAxisAlignment: MainAxisAlignment.center,
58+
children: [
59+
TextButton(
60+
onPressed: () {
61+
Navigator.push(
62+
context,
63+
MaterialPageRoute(
64+
builder: (context) => const PingableDevices(),
65+
),
66+
);
67+
},
68+
child: const Text('Pingable Devices'),
69+
),
70+
const SizedBox(height: 20, width: double.infinity),
71+
TextButton(
72+
onPressed: () {
73+
Navigator.push(
74+
context,
75+
MaterialPageRoute(
76+
builder: (context) => const PortScannerPage(),
77+
),
78+
);
79+
},
80+
child: const Text('Port Scanner'),
81+
),
82+
],
10883
),
10984
);
11085
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:network_tools_flutter/network_tools_flutter.dart';
3+
4+
class PingableDevices extends StatefulWidget {
5+
const PingableDevices({super.key});
6+
7+
@override
8+
State<PingableDevices> createState() => _PingableDevicesState();
9+
}
10+
11+
class _PingableDevicesState extends State<PingableDevices> {
12+
List<ActiveHost> activeHosts = [];
13+
14+
@override
15+
void initState() {
16+
super.initState();
17+
NetInterface.localInterface().then((value) {
18+
final NetInterface? netInt = value;
19+
if (netInt == null) {
20+
return;
21+
}
22+
HostScannerFlutter.getAllPingableDevices(netInt.networkId).listen((host) {
23+
setState(() {
24+
activeHosts.add(host);
25+
});
26+
}).onError((e) {
27+
print('Error $e');
28+
});
29+
});
30+
}
31+
32+
@override
33+
Widget build(BuildContext context) {
34+
return Scaffold(
35+
appBar: AppBar(
36+
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
37+
title: const Text('Pingable Devices'),
38+
),
39+
body: Center(
40+
child: activeHosts.isEmpty
41+
? const CircularProgressIndicator()
42+
: ListView.builder(
43+
itemCount: activeHosts.length,
44+
itemBuilder: (context, index) {
45+
return ListTile(
46+
title: Text(activeHosts[index].address),
47+
);
48+
},
49+
),
50+
),
51+
);
52+
}
53+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:network_tools_flutter/network_tools_flutter.dart';
3+
4+
class PortScannerPage extends StatefulWidget {
5+
const PortScannerPage({super.key});
6+
7+
@override
8+
State<PortScannerPage> createState() => _PortScannerPageState();
9+
}
10+
11+
class _PortScannerPageState extends State<PortScannerPage> {
12+
List<ActiveHost> activeHosts = [];
13+
14+
@override
15+
void initState() {
16+
super.initState();
17+
NetInterface.localInterface().then((value) {
18+
final NetInterface? netInt = value;
19+
if (netInt == null) {
20+
return;
21+
}
22+
String subnet =
23+
netInt.ipAddress.substring(0, netInt.ipAddress.lastIndexOf('.'));
24+
HostScanner.scanDevicesForSinglePort(subnet, 53).listen((host) {
25+
setState(() {
26+
activeHosts.add(host);
27+
});
28+
}).onError((e) {
29+
print('Error $e');
30+
});
31+
});
32+
}
33+
34+
@override
35+
Widget build(BuildContext context) {
36+
return Scaffold(
37+
appBar: AppBar(
38+
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
39+
title: const Text('Port Scanner'),
40+
),
41+
body: Center(
42+
child: activeHosts.isEmpty
43+
? const CircularProgressIndicator()
44+
: ListView.builder(
45+
itemCount: activeHosts.length,
46+
itemBuilder: (context, index) {
47+
return ListTile(
48+
title: Text(activeHosts[index].address),
49+
);
50+
},
51+
),
52+
),
53+
);
54+
}
55+
}

example/pubspec.lock

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ packages:
5353
dependency: transitive
5454
description:
5555
name: collection
56-
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
56+
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
5757
url: "https://pub.dev"
5858
source: hosted
59-
version: "1.17.2"
59+
version: "1.18.0"
6060
crypto:
6161
dependency: transitive
6262
description:
@@ -239,10 +239,10 @@ packages:
239239
dependency: transitive
240240
description:
241241
name: meta
242-
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
242+
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
243243
url: "https://pub.dev"
244244
source: hosted
245-
version: "1.9.1"
245+
version: "1.10.0"
246246
multicast_dns:
247247
dependency: transitive
248248
description:
@@ -265,7 +265,7 @@ packages:
265265
path: ".."
266266
relative: true
267267
source: path
268-
version: "1.0.3"
268+
version: "1.0.4"
269269
path:
270270
dependency: transitive
271271
description:
@@ -379,18 +379,18 @@ packages:
379379
dependency: transitive
380380
description:
381381
name: stack_trace
382-
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
382+
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
383383
url: "https://pub.dev"
384384
source: hosted
385-
version: "1.11.0"
385+
version: "1.11.1"
386386
stream_channel:
387387
dependency: transitive
388388
description:
389389
name: stream_channel
390-
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
390+
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
391391
url: "https://pub.dev"
392392
source: hosted
393-
version: "2.1.1"
393+
version: "2.1.2"
394394
string_scanner:
395395
dependency: transitive
396396
description:
@@ -419,10 +419,10 @@ packages:
419419
dependency: transitive
420420
description:
421421
name: test_api
422-
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
422+
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
423423
url: "https://pub.dev"
424424
source: hosted
425-
version: "0.6.0"
425+
version: "0.6.1"
426426
typed_data:
427427
dependency: transitive
428428
description:
@@ -459,10 +459,10 @@ packages:
459459
dependency: transitive
460460
description:
461461
name: web
462-
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
462+
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
463463
url: "https://pub.dev"
464464
source: hosted
465-
version: "0.1.4-beta"
465+
version: "0.3.0"
466466
win32:
467467
dependency: transitive
468468
description:
@@ -488,5 +488,5 @@ packages:
488488
source: hosted
489489
version: "3.1.2"
490490
sdks:
491-
dart: ">=3.1.0 <4.0.0"
491+
dart: ">=3.2.0-194.0.dev <4.0.0"
492492
flutter: ">=3.7.0"

0 commit comments

Comments
 (0)