init: rough companion app stub
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../data/sources/localiser/realtime_data_client.dart';
|
||||
import '../../../providers.dart';
|
||||
|
||||
class StepAdminUser extends ConsumerStatefulWidget {
|
||||
const StepAdminUser({super.key, required this.onComplete});
|
||||
|
||||
final VoidCallback onComplete;
|
||||
|
||||
@override
|
||||
ConsumerState<StepAdminUser> createState() => _StepAdminUserState();
|
||||
}
|
||||
|
||||
class _StepAdminUserState extends ConsumerState<StepAdminUser> {
|
||||
final _usernameController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
bool _loading = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usernameController.dispose();
|
||||
_passwordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
_error = null;
|
||||
});
|
||||
try {
|
||||
final username = _usernameController.text.trim();
|
||||
final password = _passwordController.text;
|
||||
|
||||
final token = await ref.read(onboardingRepositoryProvider).createAdminUser(
|
||||
username: username,
|
||||
password: password,
|
||||
);
|
||||
|
||||
ref.read(authTokenProvider.notifier).state = token;
|
||||
|
||||
final config = ref.read(serverConfigProvider)!;
|
||||
final realtime = RealtimeDataClient(config: config, token: token);
|
||||
await realtime.connect();
|
||||
ref.read(realtimeDataClientProvider.notifier).state = realtime;
|
||||
|
||||
await ref
|
||||
.read(credentialStoreProvider)
|
||||
.save((username: username, password: password));
|
||||
|
||||
widget.onComplete();
|
||||
} catch (e) {
|
||||
setState(() => _error = e.toString());
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Create admin account',
|
||||
style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 24),
|
||||
TextField(
|
||||
controller: _usernameController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Username',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(_error!,
|
||||
style:
|
||||
TextStyle(color: Theme.of(context).colorScheme.error)),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _loading ? null : _submit,
|
||||
child: _loading
|
||||
? const SizedBox.square(
|
||||
dimension: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Text('Create account'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class StepDone extends StatelessWidget {
|
||||
const StepDone({super.key, required this.onComplete});
|
||||
|
||||
final VoidCallback onComplete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Icon(Icons.check_circle_outline, size: 72),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'Setup complete',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Your floor plan and sensors are configured. You can add more sensors and tags at any time from the main screen.',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
FilledButton(
|
||||
onPressed: onComplete,
|
||||
child: const Text('Go to floor plan'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class StepFloorPlan extends StatelessWidget {
|
||||
const StepFloorPlan({super.key, required this.onComplete});
|
||||
|
||||
final VoidCallback onComplete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Draw floor plan',
|
||||
style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 16),
|
||||
// TODO: embed KonvaWebView in editor mode (no live overlays).
|
||||
// User draws rooms, sets scale, then taps Continue.
|
||||
const Expanded(child: Placeholder()),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: onComplete,
|
||||
child: const Text('Continue'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../ble_provision/ble_provision_sheet.dart';
|
||||
|
||||
class StepSensors extends StatelessWidget {
|
||||
const StepSensors({super.key, required this.onComplete});
|
||||
|
||||
final VoidCallback onComplete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Enroll sensors', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 8),
|
||||
const Text('Add at least one sensor to continue.'),
|
||||
const SizedBox(height: 16),
|
||||
// TODO: list of already-enrolled sensors with placement status.
|
||||
const Expanded(child: Placeholder()),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton.icon(
|
||||
icon: const Icon(Icons.bluetooth),
|
||||
label: const Text('Add sensor'),
|
||||
onPressed: () => showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
builder: (_) => const BleProvisionSheet(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
FilledButton(
|
||||
onPressed: onComplete,
|
||||
child: const Text('Continue'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class StepTags extends StatelessWidget {
|
||||
const StepTags({super.key, required this.onComplete});
|
||||
|
||||
final VoidCallback onComplete;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Enroll tags', style: Theme.of(context).textTheme.titleLarge),
|
||||
const SizedBox(height: 8),
|
||||
const Text('Tags are optional here — you can enroll them later.'),
|
||||
const SizedBox(height: 16),
|
||||
// TODO: BLE scan list + enrolled tag list, similar to StepSensors.
|
||||
const Expanded(child: Placeholder()),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: onComplete,
|
||||
child: const Text('Continue'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user