@@ -17,9 +17,28 @@ class PeersScreen extends ConsumerStatefulWidget {
1717class _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