@@ -36,8 +36,8 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
3636 }
3737
3838 Future <void > _initSelectedMicrophone () async {
39- if (widget.device is MicrophoneManager ) {
40- final mic = await ( widget.device as MicrophoneManager ).getMicrophone ();
39+ if (widget.device. hasCapability < MicrophoneManager >() ) {
40+ final mic = await widget.device. requireCapability < MicrophoneManager >( ).getMicrophone ();
4141 setState (() {
4242 selectedMicrophone = mic;
4343 });
@@ -67,10 +67,10 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
6767 mainAxisAlignment: MainAxisAlignment .center,
6868 children: [
6969 BatteryStateView (device: widget.device),
70- if (widget.device is StereoDevice )
70+ if (widget.device. hasCapability < StereoDevice >() )
7171 Padding (
7272 padding: const EdgeInsets .only (left: 8.0 ),
73- child: StereoPosLabel (device: widget.device as StereoDevice ),
73+ child: StereoPosLabel (device: widget.device. requireCapability < StereoDevice >() ),
7474 ),
7575 ],
7676 ),
@@ -79,7 +79,7 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
7979 Row (
8080 mainAxisAlignment: MainAxisAlignment .spaceEvenly,
8181 children: [
82- if (widget.device is SystemDevice && ( widget.device as SystemDevice ).isConnectedViaSystem)
82+ if (widget.device. hasCapability < SystemDevice >() && widget.device. requireCapability < SystemDevice >( ).isConnectedViaSystem)
8383 PlatformElevatedButton (
8484 child: PlatformText ("Forget Device" ),
8585 onPressed: () {
@@ -112,12 +112,12 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
112112 ],
113113 ),
114114 // MARK: Audio Mode
115- if (widget.device is AudioModeManager )
116- AudioModeWidget (device: widget.device as AudioModeManager ),
115+ if (widget.device. hasCapability < AudioModeManager >() )
116+ AudioModeWidget (device: widget.device. requireCapability < AudioModeManager >() ),
117117 // MARK: Microphone Control
118- if (widget.device is MicrophoneManager )
118+ if (widget.device. hasCapability < MicrophoneManager >() )
119119 MicrophoneSelectionWidget (
120- device: widget.device as MicrophoneManager ,
120+ device: widget.device. requireCapability < MicrophoneManager >() ,
121121 ),
122122 // MARK: Device info
123123 PlatformText ("Device Info" , style: Theme .of (context).textTheme.titleSmall),
@@ -129,14 +129,14 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
129129 subtitle: PlatformText (widget.device.deviceId),
130130 ),
131131 // MARK: Device Identifier
132- if (widget.device is DeviceIdentifier )
132+ if (widget.device. hasCapability < DeviceIdentifier >() )
133133 PlatformListTile (
134134 title: PlatformText (
135135 "Device Identifier" ,
136136 style: Theme .of (context).textTheme.bodyLarge,
137137 ),
138138 subtitle: FutureBuilder (
139- future: ( widget.device as DeviceIdentifier )
139+ future: widget.device. requireCapability < DeviceIdentifier >( )
140140 .readDeviceIdentifier (),
141141 builder: (context, snapshot) {
142142 if (snapshot.connectionState == ConnectionState .done) {
@@ -155,15 +155,15 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
155155 ),
156156 ),
157157 // MARK: Device Firmware Version
158- if (widget.device is DeviceFirmwareVersion )
158+ if (widget.device. hasCapability < DeviceFirmwareVersion >() )
159159 PlatformListTile (
160160 title: PlatformText (
161161 "Firmware Version" ,
162162 style: Theme .of (context).textTheme.bodyLarge,
163163 ),
164164 subtitle: Row (children: [
165165 FutureBuilder (
166- future: ( widget.device as DeviceFirmwareVersion )
166+ future: widget.device. requireCapability < DeviceFirmwareVersion >( )
167167 .readDeviceFirmwareVersion (),
168168 builder: (context, snapshot) {
169169 if (snapshot.connectionState == ConnectionState .done) {
@@ -181,7 +181,7 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
181181 },
182182 ),
183183 FutureBuilder (
184- future: ( widget.device as DeviceFirmwareVersion )
184+ future: widget.device. requireCapability < DeviceFirmwareVersion >( )
185185 .checkFirmwareSupport (),
186186 builder: (context, snapshot) {
187187 if (snapshot.connectionState == ConnectionState .done) {
@@ -222,14 +222,14 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
222222 ),
223223 ),
224224 // MARK: Device Hardware Version
225- if (widget.device is DeviceHardwareVersion )
225+ if (widget.device. hasCapability < DeviceHardwareVersion >() )
226226 PlatformListTile (
227227 title: PlatformText (
228228 "Hardware Version" ,
229229 style: Theme .of (context).textTheme.bodyLarge,
230230 ),
231231 subtitle: FutureBuilder (
232- future: ( widget.device as DeviceHardwareVersion )
232+ future: widget.device. requireCapability < DeviceHardwareVersion >( )
233233 .readDeviceHardwareVersion (),
234234 builder: (context, snapshot) {
235235 if (snapshot.connectionState == ConnectionState .done) {
@@ -249,17 +249,17 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
249249 ),
250250
251251 // MARK: Status LED control
252- if (widget.device is StatusLed ) ...[
252+ if (widget.device. hasCapability < StatusLed >() ) ...[
253253 PlatformText (
254254 "Control Status LED" ,
255255 style: Theme .of (context).textTheme.titleSmall,
256256 ),
257257 StatusLEDControlWidget (
258- statusLED: widget.device as StatusLed ,
259- rgbLed: widget.device as RgbLed ,
258+ statusLED: widget.device. requireCapability < StatusLed >() ,
259+ rgbLed: widget.device. requireCapability < RgbLed >() ,
260260 ),
261- ] else if (widget.device is RgbLed &&
262- widget.device is ! StatusLed ) ...[
261+ ] else if (widget.device. hasCapability < RgbLed >() &&
262+ ! widget.device. hasCapability < StatusLed >() ) ...[
263263 PlatformText (
264264 "Control RGB LED" ,
265265 style: Theme .of (context).textTheme.titleSmall,
@@ -269,18 +269,18 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
269269 "LED Color" ,
270270 style: Theme .of (context).textTheme.bodyLarge,
271271 ),
272- trailing: RgbControlView (rgbLed: widget.device as RgbLed ),
272+ trailing: RgbControlView (rgbLed: widget.device. requireCapability < RgbLed >() ),
273273 ),
274274 ],
275275
276276 // MARK: Device Battery State
277- if (widget.device is BatteryEnergyStatusService ) ...[
277+ if (widget.device. hasCapability < BatteryEnergyStatusService >() ) ...[
278278 PlatformText (
279279 "Battery Energy Status" ,
280280 style: Theme .of (context).textTheme.titleSmall,
281281 ),
282282 StreamBuilder <BatteryEnergyStatus >(
283- stream: ( widget.device as BatteryEnergyStatusService )
283+ stream: widget.device. requireCapability < BatteryEnergyStatusService >( )
284284 .energyStatusStream,
285285 builder: (context, snapshot) {
286286 if (snapshot.connectionState == ConnectionState .waiting) {
@@ -326,13 +326,13 @@ class _DeviceDetailPageState extends State<DeviceDetailPage> {
326326 ],
327327
328328 // MARK: Battery Health
329- if (widget.device is BatteryHealthStatusService ) ...[
329+ if (widget.device. hasCapability < BatteryHealthStatusService >() ) ...[
330330 PlatformText (
331331 "Battery Health Status" ,
332332 style: Theme .of (context).textTheme.titleSmall,
333333 ),
334334 StreamBuilder <BatteryHealthStatus >(
335- stream: ( widget.device as BatteryHealthStatusService )
335+ stream: widget.device. requireCapability < BatteryHealthStatusService >( )
336336 .healthStatusStream,
337337 builder: (context, snapshot) {
338338 if (snapshot.connectionState == ConnectionState .waiting) {
0 commit comments