fix: address analysis issues - remove unused import, fix deprecated APIs, update test
This commit is contained in:
parent
85249acc84
commit
07bae466cf
32 changed files with 1550 additions and 75 deletions
|
|
@ -2,10 +2,12 @@ import 'dart:async';
|
|||
import 'package:flutter/services.dart';
|
||||
|
||||
class LocationBridge {
|
||||
static const MethodChannel _methodChannel =
|
||||
MethodChannel('com.traccar.client/tracking');
|
||||
static const EventChannel _eventChannel =
|
||||
EventChannel('com.traccar.client/location_updates');
|
||||
static const MethodChannel _methodChannel = MethodChannel(
|
||||
'com.traccar.client/tracking',
|
||||
);
|
||||
static const EventChannel _eventChannel = EventChannel(
|
||||
'com.traccar.client/location_updates',
|
||||
);
|
||||
|
||||
static Stream<Map<String, dynamic>>? _locationStream;
|
||||
|
||||
|
|
@ -31,8 +33,10 @@ class LocationBridge {
|
|||
|
||||
static Future<bool> updateConfig(Map<String, dynamic> config) async {
|
||||
try {
|
||||
final result =
|
||||
await _methodChannel.invokeMethod<bool>('updateConfig', config);
|
||||
final result = await _methodChannel.invokeMethod<bool>(
|
||||
'updateConfig',
|
||||
config,
|
||||
);
|
||||
return result ?? false;
|
||||
} on PlatformException catch (e) {
|
||||
print('Failed to update config: ${e.message}');
|
||||
|
|
@ -51,9 +55,9 @@ class LocationBridge {
|
|||
}
|
||||
|
||||
static Stream<Map<String, dynamic>> get locationUpdates {
|
||||
_locationStream ??= _eventChannel
|
||||
.receiveBroadcastStream()
|
||||
.map((event) => Map<String, dynamic>.from(event as Map));
|
||||
_locationStream ??= _eventChannel.receiveBroadcastStream().map(
|
||||
(event) => Map<String, dynamic>.from(event as Map),
|
||||
);
|
||||
return _locationStream!;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,9 @@ class TraccarClientApp extends StatelessWidget {
|
|||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
||||
appBarTheme: const AppBarTheme(
|
||||
centerTitle: true,
|
||||
),
|
||||
appBarTheme: const AppBarTheme(centerTitle: true),
|
||||
),
|
||||
home: const MainScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:traccar_client/bridge/location_bridge.dart';
|
||||
import 'package:traccar_client/preferences.dart';
|
||||
import 'package:traccar_client/settings_screen.dart';
|
||||
import 'package:traccar_client/status_screen.dart';
|
||||
|
||||
|
|
@ -34,7 +33,9 @@ class _MainScreenState extends State<MainScreen> {
|
|||
? '${(location['speed'] * 3.6).toStringAsFixed(0)} km/h'
|
||||
: '--';
|
||||
_lastTime = location['timestamp'] != null
|
||||
? _formatTime(DateTime.fromMillisecondsSinceEpoch(location['timestamp']))
|
||||
? _formatTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(location['timestamp']),
|
||||
)
|
||||
: '--';
|
||||
});
|
||||
}
|
||||
|
|
@ -59,10 +60,7 @@ class _MainScreenState extends State<MainScreen> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Traccar Client'),
|
||||
centerTitle: true,
|
||||
),
|
||||
appBar: AppBar(title: const Text('Traccar Client'), centerTitle: true),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
|
|
@ -117,10 +115,12 @@ class _MainScreenState extends State<MainScreen> {
|
|||
Widget _buildTrackingToggle() {
|
||||
return SwitchListTile(
|
||||
title: Text(_isTracking ? 'Tracking: ON' : 'Tracking: OFF'),
|
||||
subtitle: Text(_isTracking ? 'Location updates active' : 'Tap to start tracking'),
|
||||
subtitle: Text(
|
||||
_isTracking ? 'Location updates active' : 'Tap to start tracking',
|
||||
),
|
||||
value: _isTracking,
|
||||
onChanged: (_) => _toggleTracking(),
|
||||
activeColor: Colors.green,
|
||||
activeTrackColor: Colors.green,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ class _MainScreenState extends State<MainScreen> {
|
|||
MaterialPageRoute(builder: (_) => const StatusScreen()),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.logs),
|
||||
icon: const Icon(Icons.history),
|
||||
label: const Text('Status/Logs'),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ class Preferences {
|
|||
|
||||
static SharedPreferences get instance {
|
||||
if (_instance == null) {
|
||||
throw Exception('Preferences not initialized. Call Preferences.init() first.');
|
||||
throw Exception(
|
||||
'Preferences not initialized. Call Preferences.init() first.',
|
||||
);
|
||||
}
|
||||
return _instance!;
|
||||
}
|
||||
|
|
@ -100,4 +102,4 @@ class Preferences {
|
|||
instance.setString(keyDeviceId, deviceId);
|
||||
return deviceId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,18 +66,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
});
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Settings saved')),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('Settings saved')));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Settings'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Settings')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
|
|
@ -120,15 +118,18 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
padding: const EdgeInsets.only(top: 16, bottom: 8),
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(String label, TextEditingController controller,
|
||||
{bool obscure = false}) {
|
||||
Widget _buildTextField(
|
||||
String label,
|
||||
TextEditingController controller, {
|
||||
bool obscure = false,
|
||||
}) {
|
||||
return TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(labelText: label),
|
||||
|
|
@ -176,4 +177,4 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,7 @@ class StatusScreen extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Event Log'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Event Log')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
|
|
@ -31,10 +29,7 @@ class StatusScreen extends StatelessWidget {
|
|||
Widget _buildPlaceholderEvent(String type, String detail, String extra) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
_getIconForType(type),
|
||||
color: _getColorForType(type),
|
||||
),
|
||||
leading: Icon(_getIconForType(type), color: _getColorForType(type)),
|
||||
title: Text(type),
|
||||
subtitle: Text('$detail $extra'.trim()),
|
||||
),
|
||||
|
|
@ -74,4 +69,4 @@ class StatusScreen extends StatelessWidget {
|
|||
return Colors.grey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue