Files
fforte/lib/screens/intro_screen.dart

185 lines
5.7 KiB
Dart

// * Initial setup screen shown on first app launch
// * Allows users to configure:
// * - Username/Address
// * - Region settings
// * - API endpoints for server communication
// * Settings are persisted using SharedPreferences
import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Widget for initial app configuration
class IntroScreen extends StatefulWidget {
const IntroScreen({super.key});
@override
State<IntroScreen> createState() => _IntroScreenState();
}
/// State class for the intro screen
class _IntroScreenState extends State<IntroScreen> {
// Text controllers for input fields
final TextEditingController addresse1C = TextEditingController();
final TextEditingController bLandC = TextEditingController();
final TextEditingController ffApiAddress = TextEditingController();
final TextEditingController exApiAddress = TextEditingController();
// List of German states
final List<String> bundeslaender = [
'Baden-Württemberg',
'Bayern',
'Berlin',
'Brandenburg',
'Bremen',
'Hamburg',
'Hessen',
'Mecklenburg-Vorpommern',
'Niedersachsen',
'Nordrhein-Westfalen',
'Rheinland-Pfalz',
'Saarland',
'Sachsen',
'Sachsen-Anhalt',
'Schleswig-Holstein',
'Thüringen'
];
// Default selected state
String selectedBundesland = 'Sachsen';
@override
void initState() {
super.initState();
bLandC.text = selectedBundesland;
// Load saved API addresses
SharedPreferences.getInstance().then((prefs) {
setState(() {
ffApiAddress.text = prefs.getString('fotofallenApiAddress') ?? '';
exApiAddress.text = prefs.getString('exkursionenApiAddress') ?? '';
});
});
}
/// Save configuration data to SharedPreferences
Future<void> _saveData() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
// Save user inputs
await prefs.setString('addresse1', addresse1C.text);
await prefs.setString('bLand', bLandC.text);
await prefs.setString('fotofallenApiAddress', ffApiAddress.text);
await prefs.setString('exkursionenApiAddress', exApiAddress.text);
// Mark app as initialized
await prefs.setBool('isFirstLaunch', false);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('LUPUS'),
),
body: Center(
child: Container(
padding: const EdgeInsets.all(31),
child: Column(
children: [
// Username/Address input
TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.benutzername
),
controller: addresse1C,
onChanged: (value) => setState(() {
addresse1C.text = value;
}),
),
const SizedBox(height: 15),
// Region settings
Column(
children: [
Row(
children: [
Expanded(
flex: 4,
child: DropdownButton<String>(
isExpanded: true,
value: selectedBundesland,
items: bundeslaender.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? newValue) {
setState(() {
selectedBundesland = newValue!;
bLandC.text = newValue;
});
},
),
),
],
),
const SizedBox(height: 35),
// Camera trap API endpoint
Align(
alignment: Alignment.bottomLeft,
child: Text(AppLocalizations.of(context)!.ffApiAddress)
),
Row(
children: [
Expanded(
flex: 1,
child: TextField(
controller: ffApiAddress,
),
)
],
),
const SizedBox(height: 10),
// Excursion API endpoint
Align(
alignment: Alignment.bottomLeft,
child: Text(AppLocalizations.of(context)!.exApiAddress)
),
Row(
children: [
Expanded(
flex: 1,
child: TextField(
controller: exApiAddress,
),
)
],
)
],
),
const SizedBox(height: 15),
// Continue button - saves settings and goes to home
ElevatedButton(
onPressed: () {
_saveData();
Navigator.pushNamedAndRemoveUntil(
context,
'/home',
(route) => false,
);
},
child: Text(AppLocalizations.of(context)!.continueB)
)
],
),
),
),
);
}
}