eksplicit mapping af envs
This commit is contained in:
14
app/README.md
Normal file
14
app/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# app
|
||||
|
||||
Flutter mobile app for Social Proximity.
|
||||
|
||||
See [Docs/APP.md](../Docs/APP.md) for full documentation.
|
||||
|
||||
## Quick start
|
||||
|
||||
```bash
|
||||
flutter pub get
|
||||
flutter run
|
||||
```
|
||||
|
||||
Note: BLE scanning requires a physical device. Emulators do not support BLE.
|
||||
9
app/analysis_options.yaml
Normal file
9
app/analysis_options.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
linter:
|
||||
rules:
|
||||
- prefer_const_constructors
|
||||
- prefer_const_literals_to_create_immutables
|
||||
- avoid_print
|
||||
- use_super_parameters
|
||||
- prefer_single_quotes
|
||||
59
app/android/app/src/main/AndroidManifest.xml
Normal file
59
app/android/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- Internet (backend API calls) -->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<!-- BLE scanning (Android 6–11) -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||
<!-- Location required for BLE scan on Android ≤ 11 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
|
||||
<!-- BLE scanning + advertising (Android 12+) -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
|
||||
android:usesPermissionFlags="neverForLocation"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
|
||||
|
||||
<!-- System notifications (Android 13+) -->
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||
|
||||
<!-- BLE hardware feature -->
|
||||
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
|
||||
|
||||
<application
|
||||
android:label="SigHej"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:taskAffinity=""
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme"/>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2"/>
|
||||
</application>
|
||||
|
||||
<!-- Queries needed for bluetooth_le on Android 11+ -->
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.bluetooth.IBluetooth.action.CONNECT"/>
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
||||
67
app/ios/Runner/Info.plist
Normal file
67
app/ios/Runner/Info.plist
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<!-- BLE permissions -->
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>SigHej uses Bluetooth to detect nearby people who are open for conversation.</string>
|
||||
<key>NSBluetoothPeripheralUsageDescription</key>
|
||||
<string>SigHej uses Bluetooth to make you discoverable when you are open to talk.</string>
|
||||
|
||||
<!-- Location (required on older iOS for BLE scanning) -->
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string>SigHej uses your location to detect nearby conversation partners via Bluetooth.</string>
|
||||
|
||||
<!-- Background BLE scanning -->
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>bluetooth-central</string>
|
||||
<string>bluetooth-peripheral</string>
|
||||
</array>
|
||||
|
||||
<!-- Standard Flutter runner keys -->
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>SigHej</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>sighej</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(FLUTTER_BUILD_NAME)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(FLUTTER_BUILD_NUMBER)</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>CADisableMinimumFrameDurationOnPhone</key>
|
||||
<true/>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
35
app/lib/main.dart
Normal file
35
app/lib/main.dart
Normal 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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
20
app/lib/models/match_result.dart
Normal file
20
app/lib/models/match_result.dart
Normal 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,
|
||||
);
|
||||
}
|
||||
268
app/lib/screens/home_screen.dart
Normal file
268
app/lib/screens/home_screen.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
201
app/lib/screens/profile_screen.dart
Normal file
201
app/lib/screens/profile_screen.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
43
app/lib/services/api_service.dart
Normal file
43
app/lib/services/api_service.dart
Normal 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;
|
||||
}
|
||||
}
|
||||
89
app/lib/services/session_store.dart
Normal file
89
app/lib/services/session_store.dart
Normal 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
107
app/lib/theme.dart
Normal 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,
|
||||
);
|
||||
26
app/pubspec.yaml
Normal file
26
app/pubspec.yaml
Normal file
@@ -0,0 +1,26 @@
|
||||
name: sighej
|
||||
description: Social Proximity — nudging people into real, face-to-face conversation.
|
||||
publish_to: "none"
|
||||
version: 0.1.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=3.3.0 <4.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_blue_plus: ^1.31.0 # BLE scanning and advertising
|
||||
http: ^1.2.0 # REST API client
|
||||
flutter_local_notifications: ^18.0.0 # Rich system notifications (no Firebase needed)
|
||||
provider: ^6.1.0 # State management
|
||||
shared_preferences: ^2.2.0 # Persist interests locally
|
||||
permission_handler: ^11.3.0 # BLE + location permissions
|
||||
uuid: ^4.3.0 # Ephemeral token generation
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
flutter_lints: ^4.0.0
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
30
app/setup.sh
Normal file
30
app/setup.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
# One-time setup: generate native Android + iOS platform files for the SigHej Flutter app.
|
||||
# Run this once from the project root (SigHej/) or from app/:
|
||||
# cd app && bash setup.sh
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
echo "📱 Generating Flutter platform files..."
|
||||
flutter create \
|
||||
--platforms=android,ios \
|
||||
--project-name sighej \
|
||||
--org dk.sighej \
|
||||
.
|
||||
|
||||
echo "📦 Installing dependencies..."
|
||||
flutter pub get
|
||||
|
||||
echo "✅ Setup complete."
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " Android: open app/android/ in Android Studio and run on device/emulator"
|
||||
echo " iOS: open app/ios/Runner.xcworkspace in Xcode and run on device/simulator"
|
||||
echo ""
|
||||
echo "⚠️ After running flutter create, copy the permission files:"
|
||||
echo " The AndroidManifest.xml and Info.plist in this repo contain the required BLE"
|
||||
echo " and notification permissions. If flutter create overwrote them, restore with:"
|
||||
echo " git checkout app/android/app/src/main/AndroidManifest.xml"
|
||||
echo " git checkout app/ios/Runner/Info.plist"
|
||||
Reference in New Issue
Block a user