mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 00:17:40 +01:00
49 lines
1.7 KiB
Dart
49 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:swift_control/gen/app_localizations.dart';
|
|
import 'package:swift_control/utils/core.dart';
|
|
import 'package:swift_control/utils/i18n_extension.dart';
|
|
import 'package:swift_control/widgets/ui/connection_method.dart';
|
|
|
|
class ZwiftTile extends StatefulWidget {
|
|
final VoidCallback onUpdate;
|
|
|
|
const ZwiftTile({super.key, required this.onUpdate});
|
|
|
|
@override
|
|
State<ZwiftTile> createState() => _ZwiftTileState();
|
|
}
|
|
|
|
class _ZwiftTileState extends State<ZwiftTile> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ValueListenableBuilder(
|
|
valueListenable: core.zwiftEmulator.isConnected,
|
|
builder: (context, isConnected, _) {
|
|
return StatefulBuilder(
|
|
builder: (context, setState) {
|
|
return ConnectionMethod(
|
|
isStarted: core.zwiftEmulator.isAdvertising,
|
|
onChange: (value) {
|
|
core.settings.setZwiftBleEmulatorEnabled(value);
|
|
if (!value) {
|
|
core.zwiftEmulator.stopAdvertising();
|
|
} else if (value) {
|
|
core.zwiftEmulator.startAdvertising(widget.onUpdate);
|
|
}
|
|
setState(() {});
|
|
},
|
|
title: context.i18n.enableZwiftControllerBluetooth,
|
|
description: !core.zwiftEmulator.isAdvertising
|
|
? context.i18n.zwiftControllerDescription
|
|
: isConnected
|
|
? context.i18n.connected
|
|
: context.i18n.waitingForConnectionKickrBike(core.settings.getTrainerApp()?.name ?? ''),
|
|
requirements: core.permissions.getRemoteControlRequirements(),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|