Skip to content

Commit a52bd8a

Browse files
committed
WIP: trying to handle peers
1 parent d40bd5f commit a52bd8a

6 files changed

Lines changed: 210 additions & 359 deletions

File tree

ios/Runner/AppDelegate.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ import OSLog
6060
self.flutterTunnelStatus = .stopped
6161
self.stopMycelium()
6262
result(true)
63+
case "getPeerStatus":
64+
let peerStatus = getPeerStatus()
65+
result(peerStatus)
6366
default:
6467
result(FlutterMethodNotImplemented)
6568
}

lib/features/home/home_screen.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ class HomeScreen extends ConsumerWidget {
5050
_HeaderCard(
5151
status: status,
5252
onConnect: () async {
53-
await service.start(['tcp://185.69.166.7:9651']);
53+
await service.start([
54+
'tcp://185.69.166.7:9651',
55+
'tcp://188.40.132.242:9651',
56+
'tcp://209.159.146.190:9651',
57+
'tcp://5.223.43.251:9651'
58+
]);
5459
},
5560
onDisconnect: () async {
5661
await service.stop();
@@ -148,11 +153,8 @@ class _HeaderCardState extends State<_HeaderCard> {
148153
height: 48,
149154
child: ElevatedButton(
150155
style: ElevatedButton.styleFrom(
151-
backgroundColor:
152-
Theme.of(context).cardColor,
153-
foregroundColor: Theme.of(context)
154-
.colorScheme
155-
.onSurface,
156+
backgroundColor: Theme.of(context).cardColor,
157+
foregroundColor: Theme.of(context).colorScheme.onSurface,
156158
padding: const EdgeInsets.symmetric(horizontal: 16),
157159
shape: RoundedRectangleBorder(
158160
borderRadius: BorderRadius.circular(10),
@@ -196,11 +198,13 @@ class _HeaderCardState extends State<_HeaderCard> {
196198
}
197199
}
198200

199-
class _StatsRow extends StatelessWidget {
201+
class _StatsRow extends ConsumerWidget {
200202
const _StatsRow();
201203

202204
@override
203-
Widget build(BuildContext context) {
205+
Widget build(BuildContext context, WidgetRef ref) {
206+
final peers = ref.watch(peersProvider);
207+
final peersCount = peers.length;
204208
Widget tileContent(IconData icon, String title, String value) => Column(
205209
mainAxisSize: MainAxisSize.min,
206210
crossAxisAlignment: CrossAxisAlignment.center,
@@ -221,7 +225,7 @@ class _StatsRow extends StatelessWidget {
221225
child: AppCard(
222226
margin: EdgeInsets.zero,
223227
padding: const EdgeInsets.all(AppSpacing.md),
224-
child: tileContent(Icons.people, 'Peers', '8'),
228+
child: tileContent(Icons.people, 'Peers', '$peersCount'),
225229
),
226230
),
227231
const SizedBox(width: AppSpacing.lg),

lib/features/peers/peers_screen.dart

Lines changed: 82 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,28 @@ class PeersScreen extends ConsumerStatefulWidget {
1717
class _PeersScreenState extends ConsumerState<PeersScreen> {
1818
String query = '';
1919

20+
@override
21+
void initState() {
22+
super.initState();
23+
ref.read(peersProvider.notifier).startUpdates();
24+
}
25+
26+
@override
27+
void dispose() {
28+
ref.read(peersProvider.notifier).stopUpdates();
29+
super.dispose();
30+
}
31+
2032
@override
2133
Widget build(BuildContext context) {
22-
final peersAsync = ref.watch(peersFutureProvider);
34+
final peers = ref.watch(peersProvider);
35+
print("Hello ya peers");
36+
print(peers);
37+
final filtered = query.isEmpty
38+
? peers
39+
: peers
40+
.where((p) => p.toLowerCase().contains(query.toLowerCase()))
41+
.toList();
2342
return AppScaffold(
2443
title: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
2544
Row(
@@ -45,105 +64,77 @@ class _PeersScreenState extends ConsumerState<PeersScreen> {
4564
]),
4665
currentIndex: 1,
4766
onTabSelected: null,
48-
child: peersAsync.when(
49-
data: (peers) {
50-
final filtered = query.isEmpty
51-
? peers
52-
: peers
53-
.where((p) => p.toLowerCase().contains(query.toLowerCase()))
54-
.toList();
55-
if (filtered.isEmpty) {
56-
return ListView(
67+
child: ListView(
68+
children: [
69+
const SizedBox(height: AppSpacing.lg),
70+
_SearchAddBar(
71+
onChanged: (v) => setState(() => query = v), onAdd: () {}),
72+
const SizedBox(height: AppSpacing.xxl),
73+
if (filtered.isEmpty)
74+
_PeersEmptyState()
75+
else
76+
...filtered.map((p) => _PeerTile.sample(index: p.hashCode)),
77+
const SizedBox(height: AppSpacing.xxl),
78+
AppCard(
79+
child: Column(
80+
crossAxisAlignment: CrossAxisAlignment.start,
5781
children: [
58-
const SizedBox(height: AppSpacing.lg),
59-
_SearchAddBar(
60-
onChanged: (v) => setState(() => query = v), onAdd: () {}),
61-
const SizedBox(height: AppSpacing.xxl),
62-
_PeersEmptyState(),
63-
const SizedBox(height: AppSpacing.xxxl),
64-
],
65-
);
66-
}
67-
return ListView(
68-
children: [
69-
const SizedBox(height: AppSpacing.lg),
70-
_SearchAddBar(
71-
onChanged: (v) => setState(() => query = v), onAdd: () {}),
72-
const SizedBox(height: AppSpacing.xxl),
73-
if (filtered.isEmpty)
74-
_PeersEmptyState()
75-
else
76-
...filtered.map((p) => _PeerTile.sample(index: p.hashCode)),
77-
const SizedBox(height: AppSpacing.xxl),
78-
AppCard(
79-
child: Column(
80-
crossAxisAlignment: CrossAxisAlignment.start,
82+
Row(
8183
children: [
82-
Row(
83-
children: [
84-
Icon(Icons.public,
85-
size: 24,
86-
color: Theme.of(context).colorScheme.primary),
87-
const SizedBox(width: 8),
88-
Text(
89-
'Peer Summary',
90-
style: Theme.of(context).textTheme.titleMedium,
91-
),
92-
],
93-
),
94-
const SizedBox(height: AppSpacing.lg),
95-
Row(
96-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
97-
children: const [
98-
_SummaryItem(
99-
label: '5',
100-
subtitle: 'Usable',
101-
color: Colors.green),
102-
_SummaryItem(
103-
label: '2', subtitle: 'Slow', color: Colors.orange),
104-
_SummaryItem(
105-
label: '1', subtitle: 'Down', color: Colors.red),
106-
],
84+
Icon(Icons.public,
85+
size: 24, color: Theme.of(context).colorScheme.primary),
86+
const SizedBox(width: 8),
87+
Text(
88+
'Peer Summary',
89+
style: Theme.of(context).textTheme.titleMedium,
10790
),
10891
],
10992
),
110-
),
111-
const SizedBox(height: AppSpacing.lg),
112-
AppCard(
113-
child: Column(
114-
crossAxisAlignment: CrossAxisAlignment.start,
93+
const SizedBox(height: AppSpacing.lg),
94+
Row(
95+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
96+
children: const [
97+
_SummaryItem(
98+
label: '5', subtitle: 'Usable', color: Colors.green),
99+
_SummaryItem(
100+
label: '2', subtitle: 'Slow', color: Colors.orange),
101+
_SummaryItem(
102+
label: '1', subtitle: 'Down', color: Colors.red),
103+
],
104+
),
105+
],
106+
),
107+
),
108+
const SizedBox(height: AppSpacing.lg),
109+
AppCard(
110+
child: Column(
111+
crossAxisAlignment: CrossAxisAlignment.start,
112+
children: [
113+
Row(
115114
children: [
116-
Row(
117-
children: [
118-
Icon(Icons.podcasts,
119-
size: 24,
120-
color: Theme.of(context).colorScheme.primary),
121-
const SizedBox(width: 8),
122-
Text(
123-
'Network Traffic',
124-
style: Theme.of(context).textTheme.titleMedium,
125-
),
126-
],
127-
),
128-
const SizedBox(height: AppSpacing.lg),
129-
Row(
130-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
131-
children: const [
132-
_SummaryItem(
133-
label: '10.5 MB/s', subtitle: 'Total Upload'),
134-
_SummaryItem(
135-
label: '20.5 MB/s', subtitle: 'Total Download'),
136-
],
115+
Icon(Icons.podcasts,
116+
size: 24, color: Theme.of(context).colorScheme.primary),
117+
const SizedBox(width: 8),
118+
Text(
119+
'Network Traffic',
120+
style: Theme.of(context).textTheme.titleMedium,
137121
),
138122
],
139123
),
140-
),
141-
const SizedBox(height: AppSpacing.xxxl),
142-
],
143-
);
144-
},
145-
loading: () => const Center(child: CircularProgressIndicator()),
146-
error: (e, st) => Center(child: Text('Failed to load peers')),
124+
const SizedBox(height: AppSpacing.lg),
125+
Row(
126+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
127+
children: const [
128+
_SummaryItem(label: '10.5 MB/s', subtitle: 'Total Upload'),
129+
_SummaryItem(
130+
label: '20.5 MB/s', subtitle: 'Total Download'),
131+
],
132+
),
133+
],
134+
),
135+
),
136+
const SizedBox(height: AppSpacing.xxxl),
137+
],
147138
),
148139
);
149140
}

0 commit comments

Comments
 (0)