|
| 1 | +import 'package:example/pages/pingable_devices.dart'; |
| 2 | +import 'package:example/pages/port_scanner_page.dart'; |
1 | 3 | import 'package:flutter/material.dart'; |
2 | 4 | import 'package:network_tools_flutter/network_tools_flutter.dart'; |
3 | 5 | import 'package:path_provider/path_provider.dart'; |
@@ -36,75 +38,48 @@ class MyApp extends StatelessWidget { |
36 | 38 | colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), |
37 | 39 | useMaterial3: true, |
38 | 40 | ), |
39 | | - home: const MyHomePage(title: 'Network Tools Flutter'), |
| 41 | + home: const MyHomePage(), |
40 | 42 | ); |
41 | 43 | } |
42 | 44 | } |
43 | 45 |
|
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}); |
80 | 48 |
|
81 | 49 | @override |
82 | 50 | 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. |
89 | 51 | return Scaffold( |
90 | 52 | 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'), |
98 | 54 | ), |
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 | + ], |
108 | 83 | ), |
109 | 84 | ); |
110 | 85 | } |
|
0 commit comments