fix: update app to new-flutter-compatible versions

This commit is contained in:
2025-05-19 17:15:39 +02:00
parent 25ffb755c1
commit d7eefa32fe
5 changed files with 225 additions and 184 deletions

View File

@ -96,18 +96,20 @@ class SettingsCubit extends HydratedCubit<SettingsState> {
@override
SettingsState? fromJson(Map<String, dynamic> json) {
// print("fromjson $json");
final usersToDevicesMap = (json['usersToDevices'] as Map<String, dynamic>?)?.map((key, value) {
final List<String> list = List<String>.from(value as List);
return MapEntry(key, list);
}) ??
{};
final usersToDevicesMap =
(json['usersToDevices'] as Map<String, dynamic>?)?.map((key, value) {
final List<String> list = List<String>.from(value as List);
return MapEntry(key, list);
}) ??
{};
return SettingsState(
url: (json['url'] ?? '') as String,
username: (json['username'] ?? '') as String,
password: (json['password'] ?? '') as String,
usersToDevices: usersToDevicesMap,
activeDevices: Set<(String, String)>.from(List<List<String>>.from(json['activeDevices']).map((e) {
activeDevices: Set<(String, String)>.from(
List<List<String>>.from(json['activeDevices']).map((e) {
if (e.length != 2) {
return null;
} else {
@ -193,7 +195,8 @@ class _SettingsPageState extends State<SettingsPage> {
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: Colors.redAccent.withOpacity(0.8), width: 2),
border: Border.all(
color: Colors.redAccent.withOpacity(0.8), width: 2),
borderRadius: BorderRadius.circular(10)),
child: Column(
mainAxisSize: MainAxisSize.min,
@ -202,10 +205,12 @@ class _SettingsPageState extends State<SettingsPage> {
TextField(
controller: _urlController,
decoration: const InputDecoration(
labelText: 'URL (e.g. https://your-owntracks.host.com)',
labelText:
'URL (e.g. https://your-owntracks.host.com)',
border: OutlineInputBorder(),
// Adds a border to the TextField
prefixIcon: Icon(Icons.account_tree), // Adds an icon to the left
prefixIcon: Icon(
Icons.account_tree), // Adds an icon to the left
),
),
const SizedBox(height: 10),
@ -216,7 +221,8 @@ class _SettingsPageState extends State<SettingsPage> {
labelText: 'Username',
border: OutlineInputBorder(),
// Adds a border to the TextField
prefixIcon: Icon(Icons.person), // Adds an icon to the left
prefixIcon:
Icon(Icons.person), // Adds an icon to the left
),
),
const SizedBox(height: 10),
@ -229,7 +235,8 @@ class _SettingsPageState extends State<SettingsPage> {
labelText: 'Password',
border: OutlineInputBorder(),
// Adds a border to the TextField
prefixIcon: Icon(Icons.lock), // Adds an icon to the left
prefixIcon:
Icon(Icons.lock), // Adds an icon to the left
),
),
const SizedBox(
@ -238,7 +245,8 @@ class _SettingsPageState extends State<SettingsPage> {
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.warning, color: Colors.red, size: 16),
const Icon(Icons.warning,
color: Colors.red, size: 16),
// Small red exclamation mark icon
const SizedBox(width: 4),
// Space between icon and text
@ -246,7 +254,8 @@ class _SettingsPageState extends State<SettingsPage> {
'Password saved locally',
style: TextStyle(
color: Colors.red,
fontSize: 12, // Small font size for the warning text
fontSize:
12, // Small font size for the warning text
),
),
const Spacer(),
@ -274,47 +283,56 @@ class _SettingsPageState extends State<SettingsPage> {
var resultingDuration = await showDurationPicker(
context: context,
initialTime: state.historyTime,
snapToMins: 60,
baseUnit: BaseUnit.hour,
);
if (resultingDuration != null) {
if (resultingDuration.inHours == 0) {
if (context.mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Please pick a duration of 1h or more!')));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Please pick a duration of 1h or more!')));
}
} else {
settingsCubit.updateSettings(historyTime: resultingDuration);
settingsCubit.updateSettings(
historyTime: resultingDuration);
}
if (resultingDuration.inDays > 4) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Warning:\nLong durations might cause slowdowns and high data usage!')));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Warning:\nLong durations might cause slowdowns and high data usage!')));
}
}
}
},
child: Text('Set Time to Load Points (current: ${formatDuration(state.historyTime)})')),
child: Text(
'Set Time to Load Points (current: ${formatDuration(state.historyTime)})')),
const SizedBox(height: 16),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border.all(color: Colors.deepPurple.withOpacity(0.8), width: 2),
border: Border.all(
color: Colors.deepPurple.withOpacity(0.8), width: 2),
borderRadius: BorderRadius.circular(10)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: List<Widget>.from([
Center(
child: ElevatedButton.icon(
onPressed: () => context.read<SettingsCubit>().fetchDevices(),
onPressed: () => context
.read<SettingsCubit>()
.fetchDevices(),
icon: const Icon(Icons.refresh),
label: const Text('Refresh Devices'),
),
),
const SizedBox(height: 16),
]) +
List<Widget>.from(state.usersToDevices.entries.map((entry) {
List<Widget>.from(
state.usersToDevices.entries.map((entry) {
return Column(
children: [
Row(
@ -333,20 +351,26 @@ class _SettingsPageState extends State<SettingsPage> {
const Divider(),
Container(
padding: const EdgeInsets.only(left: 8),
child: Column(children: List<Widget>.from(entry.value.map((device) {
child: Column(children: List<Widget>.from(
entry.value.map((device) {
return Row(
children: [
Checkbox(
value: state.activeDevices.contains((entry.key, device)),
value: state.activeDevices
.contains((entry.key, device)),
onChanged: (newVal) {
var cubit = context.read<SettingsCubit>();
Set<(String, String)> newSet = Set.from(state.activeDevices);
var cubit =
context.read<SettingsCubit>();
Set<(String, String)> newSet =
Set.from(state.activeDevices);
if (newVal ?? false) {
newSet.add((entry.key, device));
} else {
newSet.remove((entry.key, device));
newSet.remove(
(entry.key, device));
}
cubit.updateSettings(activeDevices: newSet);
cubit.updateSettings(
activeDevices: newSet);
}),
const SizedBox(width: 8),
Text("${entry.key}:$device"),

View File

@ -139,8 +139,7 @@ class LocationSubscribeCubit extends Cubit<LocationUpdateState> {
}
}
_wsClient =
ws.expect("Estabilshing Websocket Conenction failed").toOption();
_wsClient = Some(ws.expect("Estabilshing Websocket Connection failed"));
_connectionCompleter.unwrap().complete();
_connectionCompleter = None;
@ -153,7 +152,9 @@ class LocationSubscribeCubit extends Cubit<LocationUpdateState> {
@override
Future<void> close() async {
await _wsClient.toFutureOption().map((conn) => conn.close());
await _wsClient
.toFutureOption()
.map<Future<void>>((conn) async => await conn.close());
return super.close();
}
}