@ -1,18 +1,37 @@
import ' package:flutter/foundation.dart ' show listEquals ;
import ' package:flutter/material.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:meshcore_open/connector/meshcore_connector.dart ' ;
import ' package:meshcore_open/connector/meshcore_connector.dart ' ;
import ' package:meshcore_open/models/companion_radio_stats.dart ' ;
import ' package:meshcore_open/models/companion_radio_stats.dart ' ;
import ' package:meshcore_open/l10n/l10n.dart ' ;
import ' package:meshcore_open/l10n/l10n.dart ' ;
import ' package:provider/provider.dart ' ;
import ' package:provider/provider.dart ' ;
class CompanionRadioStatsScreen extends State fu lWidget {
class CompanionRadioStatsScreen extends State less Widget {
const CompanionRadioStatsScreen ( { super . key } ) ;
const CompanionRadioStatsScreen ( { super . key } ) ;
@ override
@ override
State < CompanionRadioStatsScreen > createState ( ) = >
Widget build ( BuildContext context ) {
_CompanionRadioStatsScreenState ( ) ;
return Scaffold (
appBar: AppBar (
title: Text ( context . l10n . radioStats_screenTitle ) ,
centerTitle: true ,
) ,
body: const CompanionRadioStatsBody ( ) ,
) ;
}
}
}
class _CompanionRadioStatsScreenState extends State < CompanionRadioStatsScreen > {
/ / / Embeddable Radio Stats content ( no Scaffold ) — used by both
/ / / [ CompanionRadioStatsScreen ] and the settings shell ' s Radio Stats pane.
/ / / Acquires 1 s radio - stats polling while mounted and releases it on dispose .
class CompanionRadioStatsBody extends StatefulWidget {
const CompanionRadioStatsBody ( { super . key } ) ;
@ override
State < CompanionRadioStatsBody > createState ( ) = >
_CompanionRadioStatsBodyState ( ) ;
}
class _CompanionRadioStatsBodyState extends State < CompanionRadioStatsBody > {
final List < double > _noiseHistory = [ ] ;
final List < double > _noiseHistory = [ ] ;
static const int _maxSamples = 120 ;
static const int _maxSamples = 120 ;
MeshCoreConnector ? _connector ;
MeshCoreConnector ? _connector ;
@ -52,16 +71,9 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
final l10n = context . l10n ;
final l10n = context . l10n ;
return Scaffold (
return Selector < MeshCoreConnector , ( { bool connected , bool supported } ) > (
appBar: AppBar (
selector: ( _ , c ) = >
title: Text ( l10n . radioStats_screenTitle ) ,
( connected: c . isConnected , supported: c . supportsCompanionRadioStats ) ,
centerTitle: true ,
) ,
body: Selector < MeshCoreConnector , ( { bool connected , bool supported } ) > (
selector: ( _ , c ) = > (
connected: c . isConnected ,
supported: c . supportsCompanionRadioStats ,
) ,
builder: ( context , state , _ ) {
builder: ( context , state , _ ) {
if ( ! state . connected ) {
if ( ! state . connected ) {
return Center ( child: Text ( l10n . radioStats_notConnected ) ) ;
return Center ( child: Text ( l10n . radioStats_notConnected ) ) ;
@ -95,9 +107,7 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
const SizedBox ( height: 4 ) ,
const SizedBox ( height: 4 ) ,
Text ( l10n . radioStats_lastRssi ( stats . lastRssiDbm ) ) ,
Text ( l10n . radioStats_lastRssi ( stats . lastRssiDbm ) ) ,
Text (
Text (
l10n . radioStats_lastSnr (
l10n . radioStats_lastSnr ( stats . lastSnrDb . toStringAsFixed ( 1 ) ) ,
stats . lastSnrDb . toStringAsFixed ( 1 ) ,
) ,
) ,
) ,
Text ( l10n . radioStats_txAir ( stats . txAirSecs ) ) ,
Text ( l10n . radioStats_txAir ( stats . txAirSecs ) ) ,
Text ( l10n . radioStats_rxAir ( stats . rxAirSecs ) ) ,
Text ( l10n . radioStats_rxAir ( stats . rxAirSecs ) ) ,
@ -119,16 +129,13 @@ class _CompanionRadioStatsScreenState extends State<CompanionRadioStatsScreen> {
const SizedBox ( height: 8 ) ,
const SizedBox ( height: 8 ) ,
Text (
Text (
l10n . radioStats_chartCaption ,
l10n . radioStats_chartCaption ,
style: tt . bodySmall ? . copyWith (
style: tt . bodySmall ? . copyWith ( color: scheme . onSurfaceVariant ) ,
color: scheme . onSurfaceVariant ,
) ,
) ,
) ,
] ,
] ,
) ;
) ;
} ,
} ,
) ;
) ;
} ,
} ,
) ,
) ;
) ;
}
}
}
}
@ -233,8 +240,8 @@ class _NoiseChartPainter extends CustomPainter {
@ override
@ override
bool shouldRepaint ( covariant _NoiseChartPainter oldDelegate ) {
bool shouldRepaint ( covariant _NoiseChartPainter oldDelegate ) {
return oldDelegate . samples. length ! = samples . length | |
return oldDelegate . colorScheme ! = colorScheme | |
oldDelegate . colorScheme ! = colorScheme ;
! listEquals ( oldDelegate . samples , samples ) ;
}
}
TextPainter _yAxisLabel ( double v ) {
TextPainter _yAxisLabel ( double v ) {