mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
- Introduced a new extension for localization in Flutter with `LocalizationExtension` in `l10n.dart`. - Added a Python script `translate.py` for translating ARB/JSON localization files using a local Ollama model, preserving keys and placeholders, and handling ICU format rules.
69 lines
1.7 KiB
Dart
69 lines
1.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
|
import '../l10n/l10n.dart';
|
|
|
|
/// A reusable tile widget for displaying a MeshCore device in a list
|
|
class DeviceTile extends StatelessWidget {
|
|
final ScanResult scanResult;
|
|
final VoidCallback onTap;
|
|
|
|
const DeviceTile({
|
|
super.key,
|
|
required this.scanResult,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final device = scanResult.device;
|
|
final rssi = scanResult.rssi;
|
|
final name = device.platformName.isNotEmpty
|
|
? device.platformName
|
|
: scanResult.advertisementData.advName;
|
|
|
|
return ListTile(
|
|
leading: _buildSignalIcon(rssi),
|
|
title: Text(
|
|
name.isNotEmpty ? name : context.l10n.common_unknownDevice,
|
|
style: const TextStyle(fontWeight: FontWeight.w500),
|
|
),
|
|
subtitle: Text(device.remoteId.toString()),
|
|
trailing: ElevatedButton(
|
|
onPressed: onTap,
|
|
child: Text(context.l10n.common_connect),
|
|
),
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
|
|
Widget _buildSignalIcon(int rssi) {
|
|
IconData icon;
|
|
Color color;
|
|
|
|
if (rssi >= -60) {
|
|
icon = Icons.signal_cellular_4_bar;
|
|
color = Colors.green;
|
|
} else if (rssi >= -70) {
|
|
icon = Icons.signal_cellular_alt;
|
|
color = Colors.lightGreen;
|
|
} else if (rssi >= -80) {
|
|
icon = Icons.signal_cellular_alt_2_bar;
|
|
color = Colors.orange;
|
|
} else {
|
|
icon = Icons.signal_cellular_alt_1_bar;
|
|
color = Colors.red;
|
|
}
|
|
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(icon, color: color),
|
|
Text(
|
|
'$rssi dBm',
|
|
style: TextStyle(fontSize: 10, color: color),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|