eksplicit mapping af envs
Some checks failed
Backend CI / test (push) Has been cancelled
Flutter CI / analyze-and-test (push) Has been cancelled

This commit is contained in:
Henrik Jess Nielsen
2026-05-12 18:21:25 +02:00
parent b7a435f8b9
commit 99e9b509a0
67 changed files with 8060 additions and 9 deletions

35
app/lib/main.dart Normal file
View File

@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:sighej/screens/home_screen.dart';
import 'package:sighej/screens/profile_screen.dart';
import 'package:sighej/services/session_store.dart';
import 'package:sighej/theme.dart';
void main() {
runApp(
ChangeNotifierProvider(
create: (_) => SessionStore(),
child: const SigHejApp(),
),
);
}
class SigHejApp extends StatelessWidget {
const SigHejApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SigHej',
debugShowCheckedModeBanner: false,
theme: buildTheme(),
darkTheme: buildTheme(dark: true),
themeMode: ThemeMode.system,
home: Consumer<SessionStore>(
builder: (context, store, _) => store.hasProfile
? const HomeScreen()
: const ProfileScreen(isSetup: true),
),
);
}
}

View File

@@ -0,0 +1,20 @@
class MatchResult {
final bool match;
final List<String> sharedInterests;
final bool nudgeSent;
const MatchResult({
required this.match,
required this.sharedInterests,
required this.nudgeSent,
});
factory MatchResult.fromJson(Map<String, dynamic> json) => MatchResult(
match: json['match'] as bool? ?? false,
sharedInterests: (json['shared_interests'] as List<dynamic>?)
?.map((e) => e as String)
.toList() ??
[],
nudgeSent: json['nudge_sent'] as bool? ?? false,
);
}

View File

@@ -0,0 +1,268 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import 'package:sighej/screens/profile_screen.dart';
import 'package:sighej/services/api_service.dart';
import 'package:sighej/services/session_store.dart';
// BLE service UUID that identifies SigHej devices.
const String kSigHejServiceUuid = '1248f5a0-0000-1000-8000-00805f9b34fb';
// Manufacturer ID used in BLE advertising data (Android).
const int kManufacturerId = 0x4E58; // "NX"
final FlutterLocalNotificationsPlugin _notifications =
FlutterLocalNotificationsPlugin();
const _androidChannel = AndroidNotificationDetails(
'sighej_nudge',
'SigHej Nudges',
channelDescription: 'Notifies when a nearby person shares your interests',
importance: Importance.high,
priority: Priority.high,
icon: '@mipmap/ic_launcher',
);
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
bool _openToTalk = false;
String? _lastNudge;
StreamSubscription? _bleSub;
// Track tokens we have already matched this session to avoid spam.
final Set<String> _matchedTokens = {};
@override
void initState() {
super.initState();
_initNotifications();
}
Future<void> _initNotifications() async {
const android = AndroidInitializationSettings('@mipmap/ic_launcher');
const ios = DarwinInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
);
await _notifications.initialize(
const InitializationSettings(android: android, iOS: ios),
);
}
@override
void dispose() {
_stopScanning();
super.dispose();
}
Future<void> _toggle(SessionStore store) async {
if (_openToTalk) {
_stopScanning();
return;
}
final granted = await _requestPermissions();
if (!granted) return;
await registerSession(
store.bleToken,
store.interests,
name: store.name,
tagline: store.tagline,
);
await _startAdvertising(store.bleToken);
FlutterBluePlus.startScan(timeout: const Duration(minutes: 120));
_bleSub = FlutterBluePlus.onScanResults.listen((results) async {
for (final r in results) {
final detected = _parseSigHejToken(r);
if (detected == null ||
detected == store.bleToken ||
_matchedTokens.contains(detected)) {
continue;
}
_matchedTokens.add(detected);
await _handlePotentialMatch(store.bleToken, detected, store);
}
});
setState(() => _openToTalk = true);
}
Future<void> _startAdvertising(String token) async {
final tokenBytes = Uint8List.fromList(token.codeUnits);
try {
await FlutterBluePlus.startAdvertising(
AdvertiseData(
serviceUuids: [Guid(kSigHejServiceUuid)],
manufacturerData: [ManufacturerData(kManufacturerId, tokenBytes)],
),
);
} catch (e) {
debugPrint('BLE advertise error: $e');
}
}
void _stopScanning() {
FlutterBluePlus.stopScan();
FlutterBluePlus.stopAdvertising();
_bleSub?.cancel();
_bleSub = null;
_matchedTokens.clear();
setState(() {
_openToTalk = false;
_lastNudge = null;
});
}
Future<void> _handlePotentialMatch(
String own, String detected, SessionStore store) async {
try {
final result = await reportMatch(own, detected);
if (result == null || !result.match) return;
final interests = result.sharedInterests;
final body = interests.isEmpty
? '${store.displayName} — nogen i nærheden er åben for en snak!'
: 'Fælles interesser: ${interests.join(', ')}';
await _showNudgeNotification('SigHej — sig hej!', body);
setState(() => _lastNudge = body);
} catch (e) {
debugPrint('Match error: $e');
}
}
Future<void> _showNudgeNotification(String title, String body) async {
const details = NotificationDetails(android: _androidChannel);
await _notifications.show(
body.hashCode,
title,
body,
details,
);
}
/// Parses a SigHej BLE token from a scan result.
/// Android: reads manufacturer data with key [kManufacturerId].
/// iOS fallback: reads service data for [kSigHejServiceUuid].
String? _parseSigHejToken(ScanResult result) {
final ad = result.advertisementData;
// Filter: only process SigHej advertisers.
final hasSigHejUuid = ad.serviceUuids
.map((g) => g.toString().toLowerCase())
.contains(kSigHejServiceUuid.toLowerCase());
if (!hasSigHejUuid) return null;
// Android: manufacturer data.
final mfr = ad.manufacturerData[kManufacturerId];
if (mfr != null && mfr.isNotEmpty) {
try {
return String.fromCharCodes(mfr);
} catch (_) {}
}
// iOS fallback: service data.
final svcData = ad.serviceData[Guid(kSigHejServiceUuid)];
if (svcData != null && svcData.isNotEmpty) {
try {
return String.fromCharCodes(svcData);
} catch (_) {}
}
return null;
}
Future<bool> _requestPermissions() async {
final perms = [
Permission.bluetooth,
Permission.bluetoothScan,
Permission.bluetoothAdvertise,
Permission.bluetoothConnect,
Permission.location,
Permission.notification,
];
final statuses = await perms.request();
return statuses.values.every((s) => s.isGranted || s.isLimited);
}
@override
Widget build(BuildContext context) {
final store = context.watch<SessionStore>();
return Scaffold(
appBar: AppBar(
title: const Text('SigHej'),
actions: [
IconButton(
icon: const Icon(Icons.person_outline),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const ProfileScreen()),
),
tooltip: 'Rediger profil',
),
],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
_openToTalk ? 'You\'re open to talk' : 'Tap to open up',
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 32),
GestureDetector(
onTap: () => _toggle(store),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
width: 150,
height: 150,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _openToTalk
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.surfaceContainerHighest,
),
child: Icon(
_openToTalk ? Icons.record_voice_over : Icons.mic_off,
size: 60,
color: _openToTalk
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
if (_lastNudge != null) ...[
const SizedBox(height: 40),
Card(
margin: const EdgeInsets.symmetric(horizontal: 24),
child: Padding(
padding: const EdgeInsets.all(16),
child: Text(
_lastNudge!,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge,
),
),
),
],
],
),
),
);
}
}

View File

@@ -0,0 +1,201 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:sighej/services/session_store.dart';
const List<String> kAvailableInterests = [
'Tech',
'Musik',
'Filosofi',
'Design',
'DevOps',
'Bøger',
'Gaming',
'Fitness',
'Kunst',
'Mad',
'Rejser',
'Videnskab',
'Iværksætteri',
'Film',
'Natur',
'Kodning',
'Podcast',
'Arkitektur',
'Klima',
'Sport',
];
class ProfileScreen extends StatefulWidget {
/// If [isSetup] is true, the screen is shown as first-run onboarding.
/// If false, it's opened from the home screen as "rediger profil".
final bool isSetup;
const ProfileScreen({super.key, this.isSetup = false});
@override
State<ProfileScreen> createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
late final TextEditingController _nameCtrl;
late final TextEditingController _taglineCtrl;
late final Set<String> _selected;
@override
void initState() {
super.initState();
final store = context.read<SessionStore>();
_nameCtrl = TextEditingController(text: store.name);
_taglineCtrl = TextEditingController(text: store.tagline);
_selected = Set<String>.from(store.interests);
}
@override
void dispose() {
_nameCtrl.dispose();
_taglineCtrl.dispose();
super.dispose();
}
Future<void> _save() async {
await context.read<SessionStore>().saveProfile(
name: _nameCtrl.text.trim(),
tagline: _taglineCtrl.text.trim(),
interests: _selected.toList(),
);
if (mounted) Navigator.of(context).pop();
}
@override
Widget build(BuildContext context) {
final isSetup = widget.isSetup;
return Scaffold(
appBar: AppBar(
title: Text(isSetup ? 'Hvem er du?' : 'Din profil'),
automaticallyImplyLeading: !isSetup,
),
body: SafeArea(
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (isSetup) ...[
Text(
'SigHej sender en diskret notifikation, når nogen i nærheden deler dine interesser. '
'Ingen profiler at swipe — bare et lille vink om at starte en samtale.',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 28),
],
_SectionLabel('Kaldenavn', hint: 'Valgfrit — hvad vil du kaldes?'),
const SizedBox(height: 8),
TextField(
controller: _nameCtrl,
maxLength: 40,
textCapitalization: TextCapitalization.sentences,
decoration: const InputDecoration(
hintText: 'F.eks. "Henrik" eller "Tech-nerd"',
border: OutlineInputBorder(),
counterText: '',
),
),
const SizedBox(height: 24),
_SectionLabel(
'Hvad er du op til i dag?',
hint: 'Valgfrit — sæt tonen',
),
const SizedBox(height: 8),
TextField(
controller: _taglineCtrl,
maxLength: 80,
textCapitalization: TextCapitalization.sentences,
decoration: const InputDecoration(
hintText: 'F.eks. "Åben for en kaffesnak" eller "Op til at netværke"',
border: OutlineInputBorder(),
counterText: '',
),
),
const SizedBox(height: 24),
_SectionLabel(
'Hvad interesserer dig?',
hint: 'Vi finder folk med fælles interesser i nærheden',
),
const SizedBox(height: 12),
Wrap(
spacing: 8,
runSpacing: 8,
children: kAvailableInterests.map((interest) {
final selected = _selected.contains(interest);
return FilterChip(
label: Text(interest),
selected: selected,
onSelected: (val) => setState(
() => val
? _selected.add(interest)
: _selected.remove(interest),
),
);
}).toList(),
),
const SizedBox(height: 16),
if (_selected.isEmpty)
Text(
'Vælg mindst ét emne for at bruge SigHej.',
style: TextStyle(
color: Theme.of(context).colorScheme.error,
fontSize: 13,
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(24, 8, 24, 24),
child: FilledButton(
onPressed: _selected.isEmpty ? null : _save,
style: FilledButton.styleFrom(
minimumSize: const Size.fromHeight(52),
),
child: Text(isSetup ? 'Kom i gang' : 'Gem'),
),
),
],
),
),
);
}
}
class _SectionLabel extends StatelessWidget {
final String label;
final String? hint;
const _SectionLabel(this.label, {this.hint});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: Theme.of(context).textTheme.titleSmall),
if (hint != null) ...[
const SizedBox(height: 2),
Text(
hint!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
],
);
}
}

View File

@@ -0,0 +1,43 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:sighej/models/match_result.dart';
const _baseUrl = String.fromEnvironment('API_URL', defaultValue: 'http://10.0.2.2:8000');
/// Registers the user's profile with the backend session store.
Future<void> registerSession(
String bleToken,
List<String> interests, {
String name = '',
String tagline = '',
}) async {
final response = await http.post(
Uri.parse('$_baseUrl/session'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'ble_token': bleToken,
'interests': interests,
if (name.isNotEmpty) 'name': name,
if (tagline.isNotEmpty) 'tagline': tagline,
}),
);
if (response.statusCode != 200) {
throw Exception('Failed to register session: ${response.statusCode}');
}
}
/// Reports a detected BLE token to the backend and returns the match result.
/// Returns null if the backend returns a non-200 status (soft failure).
Future<MatchResult?> reportMatch(String ownToken, String detectedToken) async {
try {
final response = await http.post(
Uri.parse('$_baseUrl/match'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'own_token': ownToken, 'detected_token': detectedToken}),
);
if (response.statusCode != 200) return null;
return MatchResult.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
} catch (_) {
return null;
}
}

View File

@@ -0,0 +1,89 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/foundation.dart';
import 'package:uuid/uuid.dart';
/// Persists the user's profile (nickname, tagline, interests) and ephemeral BLE
/// token locally. No data is ever sent without explicit user consent (toggle).
class SessionStore extends ChangeNotifier {
static const _interestsKey = 'interests';
static const _tokenKey = 'ble_token';
static const _nameKey = 'profile_name';
static const _taglineKey = 'profile_tagline';
static const _profileDoneKey = 'profile_done';
List<String> _interests = [];
String _bleToken = '';
String _name = '';
String _tagline = '';
bool _profileDone = false;
List<String> get interests => List.unmodifiable(_interests);
String get bleToken => _bleToken;
String get name => _name;
String get tagline => _tagline;
/// True once the user has completed profile setup at least once.
bool get hasProfile => _profileDone;
/// Display name — falls back to "Anonym" if not set.
String get displayName => _name.isNotEmpty ? _name : 'Anonym';
SessionStore() {
_load();
}
Future<void> _load() async {
final prefs = await SharedPreferences.getInstance();
_interests = prefs.getStringList(_interestsKey) ?? [];
_bleToken = prefs.getString(_tokenKey) ?? _newToken(prefs);
_name = prefs.getString(_nameKey) ?? '';
_tagline = prefs.getString(_taglineKey) ?? '';
_profileDone = prefs.getBool(_profileDoneKey) ?? false;
notifyListeners();
}
String _newToken(SharedPreferences prefs) {
final token = const Uuid().v4();
prefs.setString(_tokenKey, token);
return token;
}
/// Saves the full profile in one call. Marks profile as complete.
Future<void> saveProfile({
required String name,
required String tagline,
required List<String> interests,
}) async {
final prefs = await SharedPreferences.getInstance();
await Future.wait([
prefs.setString(_nameKey, name),
prefs.setString(_taglineKey, tagline),
prefs.setStringList(_interestsKey, interests),
prefs.setBool(_profileDoneKey, true),
]);
_name = name;
_tagline = tagline;
_interests = interests;
_profileDone = true;
notifyListeners();
}
/// Reset ephemeral identity — fresh BLE token, clears profile.
Future<void> reset() async {
final prefs = await SharedPreferences.getInstance();
await Future.wait([
prefs.remove(_interestsKey),
prefs.remove(_nameKey),
prefs.remove(_taglineKey),
prefs.remove(_profileDoneKey),
]);
_interests = [];
_name = '';
_tagline = '';
_profileDone = false;
_bleToken = _newToken(prefs);
notifyListeners();
}
}

107
app/lib/theme.dart Normal file
View File

@@ -0,0 +1,107 @@
import 'package:flutter/material.dart';
// SigHej color palette — "Sunny Beach Day"
const _charcoalBlue = Color(0xFF264653); // dark surface / text
const _verdigris = Color(0xFF2A9D8F); // primary (teal-green)
const _jasmine = Color(0xFFE9C46A); // tertiary / accents
const _sandyBrown = Color(0xFFF4A261); // secondary
const _burntPeach = Color(0xFFE76F51); // error / CTA accent
ThemeData buildTheme({bool dark = false}) {
final scheme = dark ? _darkScheme : _lightScheme;
return ThemeData(
colorScheme: scheme,
useMaterial3: true,
// Slightly rounded cards
cardTheme: const CardThemeData(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16)),
),
),
// Filled buttons use primary
filledButtonTheme: FilledButtonThemeData(
style: FilledButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12)),
),
),
),
// Chips use secondary container for selected state
chipTheme: ChipThemeData(
selectedColor: scheme.secondaryContainer,
labelStyle: TextStyle(color: scheme.onSurface),
),
);
}
const _lightScheme = ColorScheme(
brightness: Brightness.light,
// Primary — Verdigris
primary: _verdigris,
onPrimary: Colors.white,
primaryContainer: Color(0xFFB2DFDB),
onPrimaryContainer: _charcoalBlue,
// Secondary — Sandy Brown
secondary: _sandyBrown,
onSecondary: Colors.white,
secondaryContainer: Color(0xFFFFE0C8),
onSecondaryContainer: _charcoalBlue,
// Tertiary — Jasmine
tertiary: _jasmine,
onTertiary: _charcoalBlue,
tertiaryContainer: Color(0xFFFFF3C4),
onTertiaryContainer: _charcoalBlue,
// Error — Burnt Peach
error: _burntPeach,
onError: Colors.white,
errorContainer: Color(0xFFFFDAD6),
onErrorContainer: Color(0xFF6B0000),
// Surface — warm off-white
surface: Color(0xFFFAF8F5),
onSurface: _charcoalBlue,
surfaceContainerHighest: Color(0xFFEDE9E3),
onSurfaceVariant: Color(0xFF4A6572),
outline: Color(0xFF8EA7B0),
outlineVariant: Color(0xFFCDD8DC),
shadow: Colors.black,
scrim: Colors.black,
inverseSurface: _charcoalBlue,
onInverseSurface: Colors.white,
inversePrimary: Color(0xFF80CBC4),
);
const _darkScheme = ColorScheme(
brightness: Brightness.dark,
primary: Color(0xFF80CBC4),
onPrimary: Color(0xFF00363A),
primaryContainer: _verdigris,
onPrimaryContainer: Color(0xFFB2DFDB),
secondary: Color(0xFFFFCC80),
onSecondary: Color(0xFF3E2000),
secondaryContainer: Color(0xFF7A3800),
onSecondaryContainer: Color(0xFFFFDDB4),
tertiary: _jasmine,
onTertiary: Color(0xFF3C2800),
tertiaryContainer: Color(0xFF564000),
onTertiaryContainer: Color(0xFFFFF3C4),
error: Color(0xFFFFB4AB),
onError: Color(0xFF6B0000),
errorContainer: _burntPeach,
onErrorContainer: Colors.white,
surface: Color(0xFF1A2A2E), // deep Charcoal Blue derived
onSurface: Color(0xFFE0EAED),
surfaceContainerHighest: Color(0xFF263238),
onSurfaceVariant: Color(0xFFB0C4CB),
outline: Color(0xFF607D8B),
outlineVariant: Color(0xFF37474F),
shadow: Colors.black,
scrim: Colors.black,
inverseSurface: Color(0xFFE0EAED),
onInverseSurface: _charcoalBlue,
inversePrimary: _verdigris,
);