backup: uncommitted changes from MAC-M9FQ0900T3 2026-05-17 15:52:58
Some checks failed
Flutter CI / analyze-and-test (push) Has been cancelled

This commit is contained in:
Henrik Jess Nielsen
2026-05-17 15:52:58 +02:00
parent 99e9b509a0
commit 0328660589
49 changed files with 2764 additions and 361 deletions

View File

@@ -0,0 +1,115 @@
/// Interesse-specifikke conversation starters.
/// Vist i nudge-kortet når et match opdages.
const Map<String, List<String>> kConversationStarters = {
'Tech': [
'Hvad arbejder du på for tiden?',
'Hvad er du mest begejstret for inden for tech lige nu?',
'Er du mere frontend eller backend?',
],
'AI': [
'Hvad bruger du AI til i hverdagen?',
'Har du prøvet noget nyt inden for AI for nylig?',
'Hvad synes du om retningen AI bevæger sig i?',
],
'Musik': [
'Hvad lytter du til for tiden?',
'Har du været til en god koncert for nylig?',
'Hvad er din go-to genre når du skal fokusere?',
],
'Sport': [
'Hvad træner du hen imod?',
'Hvad er din favoritsport at følge?',
'Motionerer du mest alene eller med andre?',
],
'Løb': [
'Hvad er din næste løbsbegivenhed?',
'Løber du mest om morgenen eller om aftenen?',
'Hvad er det bedste løbetip du har fået?',
],
'Cykling': [
'Pendler du på cykel?',
'Har du en drømmerute du gerne vil cykle?',
'Road bike eller mountainbike?',
],
'Yoga': [
'Hvilken stil yoga foretrækker du?',
'Hvornår på dagen praktiserer du helst?',
'Hvad fik dig til at starte med yoga?',
],
'Madlavning': [
'Hvad har du lavet i køkkenet for nylig?',
'Er der et køkken du er særligt glad for?',
'Hvad er din bedste quick-win opskrift?',
],
'Rejser': [
'Hvad er det seneste sted du har besøgt?',
'Har du noget på rejse-ønskesedlen?',
'Foretrækker du by eller natur når du rejser?',
],
'Bøger': [
'Hvad læser du i øjeblikket?',
'Hvad er den bedste bog du har læst det seneste år?',
'Fiktion eller non-fiktion?',
],
'Film': [
'Hvad har du set for nylig der overraskede dig?',
'Hvad er din favoritgenre?',
'Streamer du eller går du til biograf?',
],
'Gaming': [
'Hvad spiller du mest for tiden?',
'PC, konsol eller mobil?',
'Hvad er det spil du har brugt flest timer på?',
],
'Design': [
'Hvad arbejder du med inden for design?',
'Hvad inspirerer dig visuelt for tiden?',
'Digitalt eller analogt — hvad er dit udgangspunkt?',
],
'Foto': [
'Hvad fotograferer du mest?',
'Hvad er dit yndlingsudstyr?',
'Film eller digital?',
],
'Kunst': [
'Hvad er du i gang med at skabe?',
'Hvad er dit foretrukne medie?',
'Er der noget du har set for nylig der inspirerede dig?',
],
'Klima': [
'Hvad gør du selv der giver størst effekt?',
'Hvad er du mest optimistisk omkring inden for klima?',
'Følger du med i en bestemt vinkel af klimadebatten?',
],
'Filosofi': [
'Hvad er du optaget af at tænke over for tiden?',
'Er der en filosof du vender tilbage til igen og igen?',
'Hvad er det vigtigste spørgsmål ingen kan svare på?',
],
'Iværksætteri': [
'Arbejder du på noget selv for øjeblikket?',
'Hvad er den vigtigste ting du har lært som iværksætter?',
'Hvad er din største udfordring lige nu?',
],
'Meditation': [
'Hvilken form for meditation praktiserer du?',
'Hvornår på dagen fungerer det bedst for dig?',
'Hvad fik dig til at starte?',
],
'Sprog': [
'Hvilke sprog taler du?',
'Hvad er det sværeste ved at lære et nyt sprog?',
'Lærer du et nyt sprog i øjeblikket?',
],
};
/// Returnerer en tilfældig conversation starter for en given interesse.
/// Falder tilbage til en generisk starter hvis interessen ikke kendes.
String getStarter(String interest) {
final starters = kConversationStarters[interest];
if (starters == null || starters.isEmpty) {
return 'Hvad arbejder du med for tiden?';
}
final copy = List<String>.from(starters)..shuffle();
return copy.first;
}

View File

@@ -25,11 +25,13 @@ class SigHejApp extends StatelessWidget {
theme: buildTheme(),
darkTheme: buildTheme(dark: true),
themeMode: ThemeMode.system,
home: Consumer<SessionStore>(
builder: (context, store, _) => store.hasProfile
? const HomeScreen()
: const ProfileScreen(isSetup: true),
),
routes: {
'/': (context) => Consumer<SessionStore>(
builder: (context, store, _) => store.hasProfile
? const HomeScreen()
: const ProfileScreen(isSetup: true),
),
},
);
}
}

View File

@@ -1,214 +1,303 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/foundation.dart';
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/data/conversation_starters.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';
bool get _bleAvailable =>
!kIsWeb &&
(defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS);
// 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',
);
const kSigHejServiceUuid = '1248f5a0-0000-1000-8000-00805f9b34fb';
const kManufacturerId = 0x4E58;
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
class _HomeScreenState extends State<HomeScreen>
with SingleTickerProviderStateMixin {
bool _openToTalk = false;
String? _lastNudge;
StreamSubscription? _bleSub;
// Track tokens we have already matched this session to avoid spam.
final Set<String> _matchedTokens = {};
String? _lastStarter;
late final AnimationController _pulseCtrl;
late final Animation<double> _pulseAnim;
@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,
_pulseCtrl = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
);
await _notifications.initialize(
const InitializationSettings(android: android, iOS: ios),
_pulseAnim = Tween<double>(begin: 1.0, end: 1.12).animate(
CurvedAnimation(parent: _pulseCtrl, curve: Curves.easeInOut),
);
}
@override
void dispose() {
_stopScanning();
_pulseCtrl.dispose();
super.dispose();
}
Future<void> _toggle(SessionStore store) async {
if (_openToTalk) {
_stopScanning();
_pulseCtrl.stop();
_pulseCtrl.reset();
setState(() {
_openToTalk = false;
_lastNudge = null;
_lastStarter = null;
});
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);
}
});
try {
await registerSession(store.bleToken, store.interests,
name: store.name, tagline: store.tagline);
} catch (_) {}
_pulseCtrl.repeat(reverse: true);
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');
if (!_bleAvailable) {
await Future.delayed(const Duration(seconds: 3));
if (mounted && _openToTalk) {
// Demo: pick a random interest from the user's list
final interests = store.interests;
final matchedInterest =
interests.isNotEmpty ? (interests..shuffle()).first : 'Tech';
setState(() {
_lastNudge =
'Nogen i nærheden deler din interesse for $matchedInterest';
_lastStarter = getStarter(matchedInterest);
});
}
}
}
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>();
final cs = Theme.of(context).colorScheme;
final isDark = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
appBar: AppBar(
title: const Text('SigHej'),
actions: [
backgroundColor: cs.surface,
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: Column(
children: [
// ── Top bar ──────────────────────────────────────────
_TopBar(store: store),
// ── Main area ────────────────────────────────────────
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Spacer(flex: 2),
// Status text
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: Text(
_openToTalk
? 'Du er åben for en snak'
: 'Tryk for at åbne op',
key: ValueKey(_openToTalk),
style: Theme.of(context)
.textTheme
.headlineSmall
?.copyWith(
fontWeight: FontWeight.w700,
color: cs.onSurface),
textAlign: TextAlign.center,
),
),
const SizedBox(height: 8),
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: Text(
_openToTalk
? 'Søger efter folk med fælles interesser…'
: 'Lad andre vide du er klar til en samtale',
key: ValueKey('sub$_openToTalk'),
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: cs.onSurfaceVariant),
textAlign: TextAlign.center,
),
),
const SizedBox(height: 48),
// ── Big toggle button ─────────────────────
GestureDetector(
onTap: () => _toggle(store),
child: ScaleTransition(
scale: _openToTalk ? _pulseAnim : const AlwaysStoppedAnimation(1.0),
child: Stack(
alignment: Alignment.center,
children: [
// Outer glow ring
if (_openToTalk)
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: cs.primary.withAlpha(30),
),
),
// Main circle
Container(
width: 168,
height: 168,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: _openToTalk
? LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
cs.primary,
Color.lerp(cs.primary,
cs.secondary, 0.5)!,
],
)
: LinearGradient(
colors: [
cs.surfaceContainerHighest,
cs.surfaceContainerHighest,
],
),
boxShadow: _openToTalk
? [
BoxShadow(
color: cs.primary.withAlpha(100),
blurRadius: 32,
spreadRadius: 4,
)
]
: [
BoxShadow(
color: isDark
? Colors.black45
: Colors.black12,
blurRadius: 16,
offset: const Offset(0, 4),
)
],
),
child: Icon(
_openToTalk
? Icons.waving_hand_rounded
: Icons.waving_hand_outlined,
size: 68,
color: _openToTalk
? cs.onPrimary
: cs.onSurfaceVariant,
),
),
],
),
),
),
const SizedBox(height: 40),
// ── Nudge card ────────────────────────────
AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
child: _lastNudge != null
? _NudgeCard(
message: _lastNudge!,
starter: _lastStarter,
)
: const SizedBox(height: 80),
),
const Spacer(flex: 3),
// ── Interest chips ────────────────────────
if (store.interests.isNotEmpty)
_InterestRow(interests: store.interests),
const SizedBox(height: 32),
],
),
),
),
],
),
),
),
);
}
}
class _TopBar extends StatelessWidget {
final SessionStore store;
const _TopBar({required this.store});
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final top = MediaQuery.of(context).padding.top;
return Container(
padding: EdgeInsets.fromLTRB(20, top + 12, 12, 16),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDark
? [const Color(0xFF1A3A40), const Color(0xFF0F2930)]
: [const Color(0xFF2A9D8F), const Color(0xFF264653)],
),
),
child: Row(
children: [
const Icon(Icons.waving_hand, color: Colors.white, size: 22),
const SizedBox(width: 8),
const Text('SigHej',
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.w800,
letterSpacing: -0.5)),
const Spacer(),
// Display name chip
Container(
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.white.withAlpha(25),
borderRadius: BorderRadius.circular(20),
),
child: Text(
store.displayName,
style: const TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.w600),
),
),
const SizedBox(width: 4),
IconButton(
icon: const Icon(Icons.person_outline),
icon: const Icon(Icons.person_outline, color: Colors.white),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const ProfileScreen()),
),
@@ -216,51 +305,130 @@ class _HomeScreenState extends State<HomeScreen> {
),
],
),
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,
);
}
}
class _NudgeCard extends StatelessWidget {
final String message;
final String? starter;
const _NudgeCard({required this.message, this.starter});
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [cs.primaryContainer, cs.tertiaryContainer],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: cs.primary.withAlpha(40),
blurRadius: 16,
offset: const Offset(0, 4),
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: cs.primary.withAlpha(30),
borderRadius: BorderRadius.circular(12),
),
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,
child:
Icon(Icons.handshake_outlined, color: cs.primary, size: 24),
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Nogen i nærheden! 👋',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 14,
color: cs.onPrimaryContainer)),
const SizedBox(height: 3),
Text(message,
style: TextStyle(
fontSize: 13,
color: cs.onPrimaryContainer.withAlpha(200))),
if (starter != null) ...[
const SizedBox(height: 10),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 7),
decoration: BoxDecoration(
color: cs.primary.withAlpha(20),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: cs.primary.withAlpha(60), width: 1),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('💬 ',
style: TextStyle(fontSize: 13)),
Expanded(
child: Text(
'"$starter"',
style: TextStyle(
fontSize: 13,
fontStyle: FontStyle.italic,
color: cs.onPrimaryContainer,
height: 1.4,
),
),
),
],
),
),
),
),
],
],
],
],
),
),
],
),
);
}
}
class _InterestRow extends StatelessWidget {
final List<String> interests;
const _InterestRow({required this.interests});
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
return SizedBox(
height: 32,
child: ListView.separated(
scrollDirection: Axis.horizontal,
itemCount: interests.length,
separatorBuilder: (_, __) => const SizedBox(width: 6),
itemBuilder: (_, i) => Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: cs.secondaryContainer,
borderRadius: BorderRadius.circular(16),
),
child: Text(
interests[i],
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: cs.onSecondaryContainer),
),
),
),
);

View File

@@ -2,34 +2,16 @@ 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',
const 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".
/// [isSetup] = true first-run onboarding (no back button)
/// [isSetup] = false → edit mode from HomeScreen
final bool isSetup;
const ProfileScreen({super.key, this.isSetup = false});
@override
@@ -37,17 +19,22 @@ class ProfileScreen extends StatefulWidget {
}
class _ProfileScreenState extends State<ProfileScreen> {
late final TextEditingController _nameCtrl;
late final TextEditingController _taglineCtrl;
late final Set<String> _selected;
final _nameCtrl = TextEditingController();
final _taglineCtrl = TextEditingController();
final Set<String> _selected = {};
bool _triedSubmit = false;
bool _loaded = false;
@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);
void didChangeDependencies() {
super.didChangeDependencies();
if (!_loaded) {
final store = context.read<SessionStore>();
_nameCtrl.text = store.name;
_taglineCtrl.text = store.tagline;
_selected.addAll(store.interests);
_loaded = true;
}
}
@override
@@ -58,144 +45,337 @@ class _ProfileScreenState extends State<ProfileScreen> {
}
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();
setState(() => _triedSubmit = true);
if (_selected.isEmpty) return;
final store = context.read<SessionStore>();
await store.saveProfile(
name: _nameCtrl.text.trim(),
tagline: _taglineCtrl.text.trim(),
interests: _selected.toList(),
);
if (!mounted) return;
if (widget.isSetup) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => const _HomeRedirect()),
);
} else {
Navigator.of(context).pop();
}
}
@override
Widget build(BuildContext context) {
final isSetup = widget.isSetup;
final cs = Theme.of(context).colorScheme;
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,
),
backgroundColor: cs.surface,
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: Column(
children: [
// ── Gradient header ──────────────────────────────────
_Header(isSetup: widget.isSetup),
// ── Scrollable form body ─────────────────────────────
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildTextField(
context,
label: 'Kaldenavn',
hint: 'F.eks. "Henrik" eller "Tech-nerd"',
sublabel: 'Valgfrit',
controller: _nameCtrl,
maxLength: 40,
),
const SizedBox(height: 20),
_buildTextField(
context,
label: 'Hvad er du op til i dag?',
hint: '"Åben for en kaffesnak" eller "Klar til at netværke"',
sublabel: 'Valgfrit — sæt tonen',
controller: _taglineCtrl,
maxLength: 80,
),
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),
Row(children: [
Text('Interesser',
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(
fontWeight: FontWeight.w700,
color: cs.onSurface)),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: _selected.isEmpty && _triedSubmit
? cs.errorContainer
: cs.primaryContainer,
borderRadius: BorderRadius.circular(20),
),
child: Text(
'${_selected.length} valgt',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: _selected.isEmpty && _triedSubmit
? cs.onErrorContainer
: cs.onPrimaryContainer,
),
),
);
}).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,
),
]),
const SizedBox(height: 4),
Text('Vælg mindst én',
style: Theme.of(context)
.textTheme
.bodySmall
?.copyWith(color: cs.onSurfaceVariant)),
const SizedBox(height: 12),
Wrap(
spacing: 8,
runSpacing: 8,
children: kAvailableInterests.map((tag) {
final on = _selected.contains(tag);
return _InterestChip(
label: tag,
selected: on,
onTap: () => setState(() =>
on ? _selected.remove(tag) : _selected.add(tag)),
);
}).toList(),
),
],
if (_triedSubmit && _selected.isEmpty) ...[
const SizedBox(height: 8),
Text('Vælg mindst ét emne for at bruge SigHej.',
style: TextStyle(
color: cs.error, fontSize: 12)),
],
const SizedBox(height: 32),
],
),
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(24, 8, 24, 24),
child: FilledButton(
onPressed: _selected.isEmpty ? null : _save,
style: FilledButton.styleFrom(
minimumSize: const Size.fromHeight(52),
// ── Save button ──────────────────────────────────────
Padding(
padding: const EdgeInsets.fromLTRB(24, 12, 24, 32),
child: SizedBox(
width: double.infinity,
height: 54,
child: FilledButton(
onPressed: _save,
style: FilledButton.styleFrom(
backgroundColor: cs.primary,
foregroundColor: cs.onPrimary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16)),
),
child: Text(
widget.isSetup ? 'Kom i gang →' : 'Gem profil',
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.w700),
),
),
),
child: Text(isSetup ? 'Kom i gang' : 'Gem'),
),
],
),
),
),
);
}
Widget _buildTextField(
BuildContext context, {
required String label,
required String hint,
required String sublabel,
required TextEditingController controller,
required int maxLength,
}) {
final cs = Theme.of(context).colorScheme;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w700, color: cs.onSurface)),
const SizedBox(height: 2),
Text(sublabel,
style: Theme.of(context)
.textTheme
.bodySmall
?.copyWith(color: cs.onSurfaceVariant)),
const SizedBox(height: 8),
TextField(
controller: controller,
maxLength: maxLength,
textCapitalization: TextCapitalization.sentences,
style: TextStyle(color: cs.onSurface),
decoration: InputDecoration(
hintText: hint,
hintStyle: TextStyle(color: cs.onSurfaceVariant.withAlpha(160)),
counterText: '',
filled: true,
fillColor: cs.surfaceContainerHighest.withAlpha(120),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: cs.outline.withAlpha(80)),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: cs.outline.withAlpha(80)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: cs.primary, width: 2),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
),
),
],
);
}
}
class _Header extends StatelessWidget {
final bool isSetup;
const _Header({required this.isSetup});
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
return Container(
width: double.infinity,
padding: EdgeInsets.fromLTRB(
24, MediaQuery.of(context).padding.top + 32, 24, 32),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDark
? [const Color(0xFF1A3A40), const Color(0xFF0F2930)]
: [const Color(0xFF2A9D8F), const Color(0xFF264653)],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!isSetup)
IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
padding: EdgeInsets.zero,
),
Row(
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: Colors.white.withAlpha(30),
borderRadius: BorderRadius.circular(14),
),
child: const Icon(Icons.waving_hand,
color: Colors.white, size: 26),
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('SigHej',
style: TextStyle(
color: Colors.white,
fontSize: 22,
fontWeight: FontWeight.w800,
letterSpacing: -0.5)),
Text(
isSetup ? 'Fortæl lidt om dig selv' : 'Rediger profil',
style: TextStyle(
color: Colors.white.withAlpha(180), fontSize: 13),
),
],
),
],
),
if (isSetup) ...[
const SizedBox(height: 20),
Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: Colors.white.withAlpha(20),
borderRadius: BorderRadius.circular(12),
),
child: 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: TextStyle(
color: Colors.white.withAlpha(210),
fontSize: 13,
height: 1.5),
),
),
],
],
),
);
}
}
class _InterestChip extends StatelessWidget {
final String label;
final bool selected;
final VoidCallback onTap;
const _InterestChip(
{required this.label, required this.selected, required this.onTap});
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
return GestureDetector(
onTap: onTap,
child: AnimatedContainer(
duration: const Duration(milliseconds: 180),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
decoration: BoxDecoration(
color: selected ? cs.primary : cs.surfaceContainerHighest,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: selected ? cs.primary : cs.outline.withAlpha(60),
width: selected ? 0 : 1,
),
),
child: Text(
label,
style: TextStyle(
fontSize: 13,
fontWeight: selected ? FontWeight.w600 : FontWeight.w400,
color: selected ? cs.onPrimary : cs.onSurface,
),
),
),
);
}
}
class _SectionLabel extends StatelessWidget {
final String label;
final String? hint;
const _SectionLabel(this.label, {this.hint});
// Redirects to HomeScreen after profile save — avoids circular import.
class _HomeRedirect extends StatelessWidget {
const _HomeRedirect();
@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,
),
),
],
],
);
// Defer to main.dart routing which will now see hasProfile=true.
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pushNamedAndRemoveUntil('/', (_) => false);
});
return const Scaffold(body: Center(child: CircularProgressIndicator()));
}
}

View File

@@ -1,5 +1,3 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/foundation.dart';
import 'package:uuid/uuid.dart';