Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev -> Main #36

Merged
merged 15 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.0.5

1. scanPortsForSingleDevice and customDiscover supports async mode now.

## 1.0.4

1. Use network_tools v4.0.1 to fix path issue in flutter.
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Features

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
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.

## Getting started

Expand All @@ -16,8 +16,7 @@ dependencies:
flutter:
sdk: flutter

network_tools_flutter: ^1.0.1
network_tools: ^3.2.4
network_tools_flutter: ^1.0.4
```

Import package in your project
Expand All @@ -29,4 +28,4 @@ Use HostScannerFlutter and PortScannerFlutter for your flutter projects. See exa

## Additional information

You can use same methods but need to import from network_tools_flutter.
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.
36 changes: 34 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# Defines a default set of lint rules enforced for
# projects at Google. For details and rationale,
# see https://github.com/dart-lang/pedantic#enabled-lints.
# include: package:pedantic/analysis_options.yaml

# lint analysis
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

analyzer:
errors:
missing_required_param: error
missing_return: error
must_be_immutable: error
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.config.dart"
- "**/*.pb.dart"
- "**/*.pbenum.dart"
- "**/*.pbgrpc.dart"
- "**/*.pbjson.dart"
- "**/*.gr.dart"
- "**/*.md"
- "example/**"

linter:
rules:
# Use parameter order as in json response
always_put_required_named_parameters_first: true

avoid_classes_with_only_static_members: false

sort_constructors_first: true

avoid_relative_lib_imports: false
93 changes: 34 additions & 59 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:example/pages/pingable_devices.dart';
import 'package:example/pages/port_scanner_page.dart';
import 'package:flutter/material.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';
import 'package:path_provider/path_provider.dart';
Expand Down Expand Up @@ -36,75 +38,48 @@ class MyApp extends StatelessWidget {
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Network Tools Flutter'),
home: const MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
List<ActiveHost> activeHosts = [];

@override
void initState() {
super.initState();
NetInterface.localInterface().then((value) {
final netInt = value;
if (netInt != null) {
HostScannerFlutter.getAllPingableDevices(netInt.networkId)
.listen((host) {
setState(() {
activeHosts.add(host);
});
});
}
});
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
title: const Text('Home'),
),
body: Center(
child: ListView.builder(
itemCount: activeHosts.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(activeHosts[index].address),
);
},
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const PingableDevices(),
),
);
},
child: const Text('Pingable Devices'),
),
const SizedBox(height: 20, width: double.infinity),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const PortScannerPage(),
),
);
},
child: const Text('Port Scanner'),
),
],
),
);
}
Expand Down
53 changes: 53 additions & 0 deletions example/lib/pages/pingable_devices.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';

class PingableDevices extends StatefulWidget {
const PingableDevices({super.key});

@override
State<PingableDevices> createState() => _PingableDevicesState();
}

class _PingableDevicesState extends State<PingableDevices> {
List<ActiveHost> activeHosts = [];

@override
void initState() {
super.initState();
NetInterface.localInterface().then((value) {
final NetInterface? netInt = value;
if (netInt == null) {
return;
}
HostScannerFlutter.getAllPingableDevices(netInt.networkId).listen((host) {
setState(() {
activeHosts.add(host);
});
}).onError((e) {
print('Error $e');
});
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Pingable Devices'),
),
body: Center(
child: activeHosts.isEmpty
? const CircularProgressIndicator()
: ListView.builder(
itemCount: activeHosts.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(activeHosts[index].address),
);
},
),
),
);
}
}
55 changes: 55 additions & 0 deletions example/lib/pages/port_scanner_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'package:flutter/material.dart';
import 'package:network_tools_flutter/network_tools_flutter.dart';

class PortScannerPage extends StatefulWidget {
const PortScannerPage({super.key});

@override
State<PortScannerPage> createState() => _PortScannerPageState();
}

class _PortScannerPageState extends State<PortScannerPage> {
List<ActiveHost> activeHosts = [];

@override
void initState() {
super.initState();
NetInterface.localInterface().then((value) {
final NetInterface? netInt = value;
if (netInt == null) {
return;
}
String subnet =
netInt.ipAddress.substring(0, netInt.ipAddress.lastIndexOf('.'));
HostScanner.scanDevicesForSinglePort(subnet, 53).listen((host) {
setState(() {
activeHosts.add(host);
});
}).onError((e) {
print('Error $e');
});
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Port Scanner'),
),
body: Center(
child: activeHosts.isEmpty
? const CircularProgressIndicator()
: ListView.builder(
itemCount: activeHosts.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(activeHosts[index].address),
);
},
),
),
);
}
}
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -239,10 +239,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
multicast_dns:
dependency: transitive
description:
Expand All @@ -265,7 +265,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.3"
version: "1.0.4"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -379,18 +379,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand Down Expand Up @@ -419,10 +419,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -459,10 +459,10 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
win32:
dependency: transitive
description:
Expand All @@ -488,5 +488,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.1.0 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.7.0"
Loading
Loading