Added app to repository
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 23s
All checks were successful
Deploy Docs / build-and-deploy (push) Successful in 23s
This commit is contained in:
11
software/app/lib/constants.dart
Normal file
11
software/app/lib/constants.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
class LasertagUUIDs {
|
||||
static const String base = "03afe2cf-6c64-4a22-9289-c3ae820c";
|
||||
static const String provService = "${base}1000";
|
||||
static const String typeChar = "${base}1008";
|
||||
|
||||
// Gerätetypen aus deiner ble_mgmt.h
|
||||
static const int typeLeader = 0x01;
|
||||
static const int typeWeapon = 0x02;
|
||||
static const int typeVest = 0x03;
|
||||
static const int typeBeacon = 0x04;
|
||||
}
|
||||
10
software/app/lib/l10n/app_de.arb
Normal file
10
software/app/lib/l10n/app_de.arb
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"@@locale": "de",
|
||||
"appTitle": "Lasertag Mission Control",
|
||||
"selectLeader": "Leader auswählen",
|
||||
"searching": "Suche nach Knoten...",
|
||||
"typeLeader": "Spiel-Leiter",
|
||||
"typeWeapon": "Waffe",
|
||||
"typeVest": "Weste",
|
||||
"typeBeacon": "Beacon"
|
||||
}
|
||||
170
software/app/lib/l10n/app_localizations.dart
Normal file
170
software/app/lib/l10n/app_localizations.dart
Normal file
@@ -0,0 +1,170 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
|
||||
import 'app_localizations_de.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
/// Callers can lookup localized strings with an instance of AppLocalizations
|
||||
/// returned by `AppLocalizations.of(context)`.
|
||||
///
|
||||
/// Applications need to include `AppLocalizations.delegate()` in their app's
|
||||
/// `localizationDelegates` list, and the locales they support in the app's
|
||||
/// `supportedLocales` list. For example:
|
||||
///
|
||||
/// ```dart
|
||||
/// import 'l10n/app_localizations.dart';
|
||||
///
|
||||
/// return MaterialApp(
|
||||
/// localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
/// supportedLocales: AppLocalizations.supportedLocales,
|
||||
/// home: MyApplicationHome(),
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
/// ## Update pubspec.yaml
|
||||
///
|
||||
/// Please make sure to update your pubspec.yaml to include the following
|
||||
/// packages:
|
||||
///
|
||||
/// ```yaml
|
||||
/// dependencies:
|
||||
/// # Internationalization support.
|
||||
/// flutter_localizations:
|
||||
/// sdk: flutter
|
||||
/// intl: any # Use the pinned version from flutter_localizations
|
||||
///
|
||||
/// # Rest of dependencies
|
||||
/// ```
|
||||
///
|
||||
/// ## iOS Applications
|
||||
///
|
||||
/// iOS applications define key application metadata, including supported
|
||||
/// locales, in an Info.plist file that is built into the application bundle.
|
||||
/// To configure the locales supported by your app, you’ll need to edit this
|
||||
/// file.
|
||||
///
|
||||
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
|
||||
/// Then, in the Project Navigator, open the Info.plist file under the Runner
|
||||
/// project’s Runner folder.
|
||||
///
|
||||
/// Next, select the Information Property List item, select Add Item from the
|
||||
/// Editor menu, then select Localizations from the pop-up menu.
|
||||
///
|
||||
/// Select and expand the newly-created Localizations item then, for each
|
||||
/// locale your application supports, add a new item and select the locale
|
||||
/// you wish to add from the pop-up menu in the Value field. This list should
|
||||
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
|
||||
/// property.
|
||||
abstract class AppLocalizations {
|
||||
AppLocalizations(String locale)
|
||||
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
||||
|
||||
final String localeName;
|
||||
|
||||
static AppLocalizations? of(BuildContext context) {
|
||||
return Localizations.of<AppLocalizations>(context, AppLocalizations);
|
||||
}
|
||||
|
||||
static const LocalizationsDelegate<AppLocalizations> delegate =
|
||||
_AppLocalizationsDelegate();
|
||||
|
||||
/// A list of this localizations delegate along with the default localizations
|
||||
/// delegates.
|
||||
///
|
||||
/// Returns a list of localizations delegates containing this delegate along with
|
||||
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
|
||||
/// and GlobalWidgetsLocalizations.delegate.
|
||||
///
|
||||
/// Additional delegates can be added by appending to this list in
|
||||
/// MaterialApp. This list does not have to be used at all if a custom list
|
||||
/// of delegates is preferred or required.
|
||||
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
|
||||
<LocalizationsDelegate<dynamic>>[
|
||||
delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
];
|
||||
|
||||
/// A list of this localizations delegate's supported locales.
|
||||
static const List<Locale> supportedLocales = <Locale>[Locale('de')];
|
||||
|
||||
/// No description provided for @appTitle.
|
||||
///
|
||||
/// In de, this message translates to:
|
||||
/// **'Lasertag Mission Control'**
|
||||
String get appTitle;
|
||||
|
||||
/// No description provided for @selectLeader.
|
||||
///
|
||||
/// In de, this message translates to:
|
||||
/// **'Leader auswählen'**
|
||||
String get selectLeader;
|
||||
|
||||
/// No description provided for @searching.
|
||||
///
|
||||
/// In de, this message translates to:
|
||||
/// **'Suche nach Knoten...'**
|
||||
String get searching;
|
||||
|
||||
/// No description provided for @typeLeader.
|
||||
///
|
||||
/// In de, this message translates to:
|
||||
/// **'Spiel-Leiter'**
|
||||
String get typeLeader;
|
||||
|
||||
/// No description provided for @typeWeapon.
|
||||
///
|
||||
/// In de, this message translates to:
|
||||
/// **'Waffe'**
|
||||
String get typeWeapon;
|
||||
|
||||
/// No description provided for @typeVest.
|
||||
///
|
||||
/// In de, this message translates to:
|
||||
/// **'Weste'**
|
||||
String get typeVest;
|
||||
|
||||
/// No description provided for @typeBeacon.
|
||||
///
|
||||
/// In de, this message translates to:
|
||||
/// **'Beacon'**
|
||||
String get typeBeacon;
|
||||
}
|
||||
|
||||
class _AppLocalizationsDelegate
|
||||
extends LocalizationsDelegate<AppLocalizations> {
|
||||
const _AppLocalizationsDelegate();
|
||||
|
||||
@override
|
||||
Future<AppLocalizations> load(Locale locale) {
|
||||
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
|
||||
}
|
||||
|
||||
@override
|
||||
bool isSupported(Locale locale) =>
|
||||
<String>['de'].contains(locale.languageCode);
|
||||
|
||||
@override
|
||||
bool shouldReload(_AppLocalizationsDelegate old) => false;
|
||||
}
|
||||
|
||||
AppLocalizations lookupAppLocalizations(Locale locale) {
|
||||
// Lookup logic when only language code is specified.
|
||||
switch (locale.languageCode) {
|
||||
case 'de':
|
||||
return AppLocalizationsDe();
|
||||
}
|
||||
|
||||
throw FlutterError(
|
||||
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
|
||||
'an issue with the localizations generation tool. Please file an issue '
|
||||
'on GitHub with a reproducible sample app and the gen-l10n configuration '
|
||||
'that was used.',
|
||||
);
|
||||
}
|
||||
31
software/app/lib/l10n/app_localizations_de.dart
Normal file
31
software/app/lib/l10n/app_localizations_de.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
// ignore: unused_import
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'app_localizations.dart';
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
/// The translations for German (`de`).
|
||||
class AppLocalizationsDe extends AppLocalizations {
|
||||
AppLocalizationsDe([String locale = 'de']) : super(locale);
|
||||
|
||||
@override
|
||||
String get appTitle => 'Lasertag Mission Control';
|
||||
|
||||
@override
|
||||
String get selectLeader => 'Leader auswählen';
|
||||
|
||||
@override
|
||||
String get searching => 'Suche nach Knoten...';
|
||||
|
||||
@override
|
||||
String get typeLeader => 'Spiel-Leiter';
|
||||
|
||||
@override
|
||||
String get typeWeapon => 'Waffe';
|
||||
|
||||
@override
|
||||
String get typeVest => 'Weste';
|
||||
|
||||
@override
|
||||
String get typeBeacon => 'Beacon';
|
||||
}
|
||||
128
software/app/lib/leader_selection_screen.dart
Normal file
128
software/app/lib/leader_selection_screen.dart
Normal file
@@ -0,0 +1,128 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
import 'package:lasertag_app/l10n/app_localizations.dart';
|
||||
import 'constants.dart';
|
||||
|
||||
class LeaderSelectionScreen extends StatefulWidget {
|
||||
const LeaderSelectionScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LeaderSelectionScreen> createState() => _LeaderSelectionScreenState();
|
||||
}
|
||||
|
||||
class _LeaderSelectionScreenState extends State<LeaderSelectionScreen> {
|
||||
// Map, um Geräte und ihren erkannten Typ zu speichern
|
||||
Map<BluetoothDevice, int> discoveredDevices = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_startDiscovery();
|
||||
}
|
||||
|
||||
void _startDiscovery() async {
|
||||
FlutterBluePlus.scanResults.listen((results) {
|
||||
for (ScanResult r in results) {
|
||||
// 1. Prüfen, ob Manufacturer Data für unsere Test-ID (0xFFFF / 65535) da ist
|
||||
final mfgData = r.advertisementData.manufacturerData[65535];
|
||||
|
||||
if (mfgData != null && mfgData.isNotEmpty) {
|
||||
int detectedType = mfgData[0]; // Das Typ-Byte vom nRF52
|
||||
|
||||
// 2. Nur hinzufügen, wenn es wirklich ein Leader (0x01) ist
|
||||
if (detectedType == LasertagUUIDs.typeLeader) {
|
||||
if (!discoveredDevices.containsKey(r.device)) {
|
||||
setState(() {
|
||||
discoveredDevices[r.device] = detectedType;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// 2. Warten, bis der Bluetooth-Adapter wirklich "on" ist
|
||||
await FlutterBluePlus.adapterState
|
||||
.where((s) => s == BluetoothAdapterState.on)
|
||||
.first;
|
||||
|
||||
// 3. Den Scan tatsächlich starten
|
||||
try {
|
||||
// Filtert nach der Service-UUID ...1000 aus ble_mgmt.c
|
||||
await FlutterBluePlus.startScan(
|
||||
withServices: [Guid(LasertagUUIDs.provService)],
|
||||
timeout: const Duration(seconds: 15),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint("Scan-Fehler: $e");
|
||||
}
|
||||
} // <--- Hier endet _startDiscovery korrekt
|
||||
|
||||
// Hilfsfunktion zur Übersetzung des Typs
|
||||
String _getLocalizedTypeName(BuildContext context, int type) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
switch (type) {
|
||||
case LasertagUUIDs.typeLeader:
|
||||
return l10n.typeLeader;
|
||||
case LasertagUUIDs.typeWeapon:
|
||||
return l10n.typeWeapon;
|
||||
case LasertagUUIDs.typeVest:
|
||||
return l10n.typeVest;
|
||||
case LasertagUUIDs.typeBeacon:
|
||||
return l10n.typeBeacon;
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(l10n.selectLeader)),
|
||||
body: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(l10n.searching),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: discoveredDevices.entries.map((entry) {
|
||||
final device = entry.key;
|
||||
final type = entry.value;
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.hub,
|
||||
// Holt sich die Akzentfarbe direkt vom Betriebssystem via Theme-Context
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
size: 32,
|
||||
),
|
||||
title: Text(
|
||||
device.platformName.isEmpty
|
||||
? "Lasertag Device"
|
||||
: device.platformName,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(
|
||||
"${_getLocalizedTypeName(context, type)} (${device.remoteId})",
|
||||
// Nutzt eine dezentere Farbe für den Untertitel
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
onTap: () => _onLeaderSelected(device),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onLeaderSelected(BluetoothDevice device) {
|
||||
debugPrint("Leader ausgewählt: ${device.platformName}");
|
||||
// Hier öffnen wir als nächstes den Config-Dialog
|
||||
}
|
||||
}
|
||||
52
software/app/lib/main.dart
Normal file
52
software/app/lib/main.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:lasertag_app/l10n/app_localizations.dart';
|
||||
import 'leader_selection_screen.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const LasertagApp());
|
||||
}
|
||||
|
||||
class LasertagApp extends StatelessWidget {
|
||||
const LasertagApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Der Builder holt die Systemfarben (Accent Color)
|
||||
return DynamicColorBuilder(
|
||||
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
||||
// --- Lokalisierung ---
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('de')],
|
||||
locale: const Locale('de'),
|
||||
|
||||
// --- Theme-Logik ---
|
||||
// Falls das OS Farben liefert, nutzen wir diese, sonst ein Standard-Blau
|
||||
theme: ThemeData(
|
||||
colorScheme: lightDynamic ?? ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
useMaterial3: true,
|
||||
),
|
||||
darkTheme: ThemeData(
|
||||
colorScheme: darkDynamic ?? ColorScheme.fromSeed(
|
||||
seedColor: Colors.blue,
|
||||
brightness: Brightness.dark
|
||||
),
|
||||
useMaterial3: true,
|
||||
),
|
||||
themeMode: ThemeMode.system, // Folgt macOS/Android Hell/Dunkel Modus
|
||||
|
||||
home: const LeaderSelectionScreen(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user