-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard_screen.dart
More file actions
98 lines (92 loc) · 3.58 KB
/
Copy pathdashboard_screen.dart
File metadata and controls
98 lines (92 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/network_service.dart';
import '../services/notification_service.dart';
import '../services/nsd_service.dart';
import '../services/settings_service.dart';
class DashboardScreen extends StatefulWidget {
const DashboardScreen({Key? key}) : super(key: key);
@override
State<DashboardScreen> createState() => _DashboardScreenState();
}
class _DashboardScreenState extends State<DashboardScreen> {
@override
void initState() {
super.initState();
// Request permissions and initialize listening when the UI loads
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<NotificationService>().init();
});
}
@override
Widget build(BuildContext context) {
final network = context.watch<NetworkService>();
final nsd = context.watch<NsdService>();
final settings = context.watch<SettingsService>();
return Scaffold(
appBar: AppBar(
title: const Text('Phone-Link Dashboard'),
actions: [
Row(
children: [
const Text('Service Enabled'),
Switch(
value: settings.isServiceEnabled,
onChanged: (val) => settings.toggleService(val),
),
],
),
const SizedBox(width: 16),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Connection Status', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
ListTile(
leading: Icon(
network.isConnected ? Icons.cloud_done : Icons.cloud_off,
color: network.isConnected ? Colors.green : Colors.red,
),
title: Text(network.isConnected ? 'Connected to Desktop' : 'Disconnected'),
trailing: network.isConnected
? TextButton(onPressed: () => network.disconnect(), child: const Text('Disconnect'))
: null,
),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Discovered Devices', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
ElevatedButton(
onPressed: nsd.isDiscovering ? () => nsd.stopScanning() : () => nsd.startScanning(),
child: Text(nsd.isDiscovering ? 'Stop Scanning' : 'Scan for Desktop'),
),
],
),
Expanded(
child: nsd.discoveredServices.isEmpty
? const Center(child: Text('No devices found on the local network.'))
: ListView.builder(
itemCount: nsd.discoveredServices.length,
itemBuilder: (context, index) {
final service = nsd.discoveredServices[index];
return ListTile(
title: Text(service.name ?? 'Unknown Device'),
subtitle: Text('${service.host ?? 'Unknown IP'}:${service.port}'),
trailing: ElevatedButton(
onPressed: network.isConnected ? null : () => network.connect(service.host!, service.port!),
child: const Text('Connect'),
),
);
},
),
),
],
),
),
);
}
}