@@ -2,33 +2,45 @@ import 'dart:async';
22
33import 'package:flutter/material.dart' ;
44import 'package:auto_size_text/auto_size_text.dart' ;
5+ import 'package:flutter_rentnerend/info_window/team_window.dart' ;
56
6- import 'md.dart' ;
7- import 'ws_client.dart' ;
8- import 'lib.dart' as lib;
7+ import '../md.dart' ;
8+ import '../ws_client.dart' ;
9+ import '../ws_client_factory.dart' ;
10+ import '../lib.dart' as lib;
911
1012
1113class InfoWindow extends StatefulWidget {
12- const InfoWindow ({super .key, required this .mdl, required this .ws });
14+ const InfoWindow ({super .key, required this .url });
1315
14- final ValueNotifier <Matchday > mdl;
15- final WSClient ws;
16+ final String url;
1617
1718 @override
1819 State <InfoWindow > createState () => _InfoWindowState ();
1920}
2021
21- class _InfoWindowState extends State <InfoWindow > {
22+ class _InfoWindowState extends State <InfoWindow > with AutomaticKeepAliveClientMixin {
2223 late ValueNotifier <Matchday > mdl;
2324 late WSClient ws;
25+ late String url;
2426 late Timer _reconnectTimer;
27+ bool ready = false ;
28+
29+ @override
30+ bool get wantKeepAlive => true ;
2531
2632 @override
2733 void initState () {
2834 super .initState ();
35+ url = widget.url;
36+
37+ final md = Matchday (Meta (), [], [], [], []);
38+ mdl = ValueNotifier (md);
2939
30- mdl = widget.mdl;
31- ws = widget.ws;
40+
41+ ws = createWSClient (url, mdl, false , true );
42+ lib.connectWS (ws);
43+ _checkReady ();
3244
3345 _reconnectTimer = Timer .periodic (const Duration (seconds: 3 ), (_) async {
3446 if (! ws.connected.value && mounted) {
@@ -38,7 +50,6 @@ class _InfoWindowState extends State<InfoWindow> {
3850
3951 startTimer ();
4052 }
41-
4253 @override
4354 void dispose () {
4455 _timer? .cancel ();
@@ -55,6 +66,19 @@ class _InfoWindowState extends State<InfoWindow> {
5566 final remainingTime = ValueNotifier <int >(0 );
5667 Timer ? _timer;
5768
69+ Future <void > _checkReady () async {
70+ final md = Matchday (Meta (), [], [], [], []);
71+
72+ await Future .doWhile (() async {
73+ await Future .delayed (Duration (milliseconds: 10 ));
74+ debugPrint ("Checking: ${mdl .value == md }" );
75+ return mdl.value == md;
76+ });
77+
78+ debugPrint ("ready" );
79+ setState (() => ready = true );
80+ }
81+
5882 void startTimer () {
5983 _timer = Timer .periodic (const Duration (milliseconds: 200 ), (_) {
6084 final curTime = mdl.value.currentTime ();
@@ -161,6 +185,9 @@ class _InfoWindowState extends State<InfoWindow> {
161185 }
162186 }
163187
188+ final int t1index = md.teams.indexOf (md.teamFromName (t1name)! );
189+ final int t2index = md.teams.indexOf (md.teamFromName (t2name)! );
190+
164191 return Container (
165192 decoration: BoxDecoration (
166193 color: md.currentGame == g ? Colors .white.withValues (alpha: 0.3 ) : null ,
@@ -169,15 +196,31 @@ class _InfoWindowState extends State<InfoWindow> {
169196 padding: EdgeInsetsGeometry .symmetric (vertical: 5 ),
170197 child: Row (children: [
171198 Expanded (flex: 10 , child: Center (child: Padding (padding: EdgeInsetsGeometry .only (left: 5 ), child: AutoSizeText (group: textGroup, maxLines: 1 , g.name)))),
172- Expanded (flex: 35 , child: Center (child: AutoSizeText (group: textGroup, maxLines: 1 , softWrap: true , t1name))),
199+ Expanded (flex: 35 , child: GestureDetector (
200+ onTap: () => Navigator .push (
201+ context,
202+ MaterialPageRoute <void >(
203+ builder: (context) => TeamWindow (mdl: mdl, ws: ws, teamIndex: t1index)
204+ )
205+ ),
206+ child: Center (child: AutoSizeText (group: textGroup, maxLines: 1 , softWrap: true , t1name))
207+ )),
173208 Expanded (flex: 20 , child: Center (child: AutoSizeText .rich (group: textGroup, maxLines: 1 , softWrap: true ,
174209 TextSpan (children: [
175210 TextSpan (text: "${t1_score ?? '?' }" , style: TextStyle (color: t1_color, fontWeight: FontWeight .bold)),
176211 const TextSpan (text: ' : ' ),
177212 TextSpan (text: "${t2_score ?? '?' }" , style: TextStyle (color: t2_color, fontWeight: FontWeight .bold))
178213 ])
179214 ))),
180- Expanded (flex: 35 , child: Center (child: AutoSizeText (group: textGroup, maxLines: 1 , softWrap: true , t2name)))
215+ Expanded (flex: 35 , child: GestureDetector (
216+ onTap: () => Navigator .push (
217+ context,
218+ MaterialPageRoute <void >(
219+ builder: (context) => TeamWindow (mdl: mdl, ws: ws, teamIndex: t2index)
220+ )
221+ ),
222+ child: Center (child: AutoSizeText (group: textGroup, maxLines: 1 , softWrap: true , t2name))
223+ )),
181224 ]),
182225 )
183226 );
@@ -224,7 +267,8 @@ class _InfoWindowState extends State<InfoWindow> {
224267
225268 return TableRow (
226269 decoration: BoxDecoration (
227- color: index > 1 ? bg : Colors .green.withValues (alpha: 0.5 ),
270+ //color: index > 1 ? bg : Colors.green.withValues(alpha: 0.5),
271+ color: bg,
228272 //borderRadius: BorderRadius.circular(40),
229273 ),
230274 children: [
@@ -247,7 +291,7 @@ class _InfoWindowState extends State<InfoWindow> {
247291
248292 Widget blockLivetable (Matchday md, Group g, Color bg) {
249293 return Padding (
250- padding: const EdgeInsets .symmetric (horizontal : 10 ),
294+ padding: const EdgeInsets .only (left : 10 , right : 10 , bottom : 20 ),
251295 child: Material (
252296 color: bg,
253297 borderRadius: BorderRadius .circular (13 ),
@@ -319,10 +363,17 @@ class _InfoWindowState extends State<InfoWindow> {
319363 Widget build (BuildContext context) {
320364 final secondBgColor = Theme .of (context).scaffoldBackgroundColor;
321365
322- return PopScope (
323- child: Scaffold (
366+ super .build (context);
367+
368+ if (! ready) {
369+ return const Scaffold (
324370 backgroundColor: Colors .black,
325- body: SingleChildScrollView (
371+ body: Center (child: CircularProgressIndicator ()),
372+ );
373+ }
374+
375+ return PopScope (
376+ child: SingleChildScrollView (
326377 child: ValueListenableBuilder <Matchday >(
327378 valueListenable: mdl,
328379 builder: (context, md, _) {
@@ -344,7 +395,6 @@ class _InfoWindowState extends State<InfoWindow> {
344395 }
345396 )
346397 )
347- )
348398 );
349399 }
350400}
0 commit comments