feat: revamp UI with dark terminal aesthetic
This commit is contained in:
parent
d673f01a2d
commit
02040081ce
3 changed files with 825 additions and 201 deletions
|
|
@ -13,7 +13,7 @@ class MainScreen extends StatefulWidget {
|
|||
State<MainScreen> createState() => _MainScreenState();
|
||||
}
|
||||
|
||||
class _MainScreenState extends State<MainScreen> {
|
||||
class _MainScreenState extends State<MainScreen> with TickerProviderStateMixin {
|
||||
StreamSubscription<Map<String, dynamic>>? _locationSubscription;
|
||||
bool _isTracking = false;
|
||||
String _lastLat = '--';
|
||||
|
|
@ -21,15 +21,26 @@ class _MainScreenState extends State<MainScreen> {
|
|||
String _lastSpeed = '--';
|
||||
String _lastTime = '--';
|
||||
|
||||
late AnimationController _pulseController;
|
||||
late Animation<double> _pulseAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pulseController = AnimationController(
|
||||
duration: const Duration(milliseconds: 1400),
|
||||
vsync: this,
|
||||
)..repeat(reverse: true);
|
||||
_pulseAnimation = Tween<double>(begin: 0.6, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _pulseController, curve: Curves.easeInOut),
|
||||
);
|
||||
_initLocationStream();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_locationSubscription?.cancel();
|
||||
_pulseController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
@ -41,18 +52,18 @@ class _MainScreenState extends State<MainScreen> {
|
|||
final lat = status?['lastLatitude'];
|
||||
final lon = status?['lastLongitude'];
|
||||
if (lat != null && lat != 0.0) {
|
||||
_lastLat = lat.toStringAsFixed(4);
|
||||
_lastLat = lat.toStringAsFixed(5);
|
||||
}
|
||||
if (lon != null && lon != 0.0) {
|
||||
_lastLon = lon.toStringAsFixed(4);
|
||||
_lastLon = lon.toStringAsFixed(5);
|
||||
}
|
||||
final speed = status?['lastSpeed'];
|
||||
if (speed != null) {
|
||||
_lastSpeed = '${(speed * 3.6).toStringAsFixed(0)} km/h';
|
||||
_lastSpeed = (speed * 3.6).toStringAsFixed(1);
|
||||
}
|
||||
final timestamp = status?['lastTimestamp'];
|
||||
if (timestamp != null) {
|
||||
_lastTime = _formatTime(
|
||||
_lastTime = _formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(timestamp),
|
||||
);
|
||||
}
|
||||
|
|
@ -62,13 +73,13 @@ class _MainScreenState extends State<MainScreen> {
|
|||
_locationSubscription = LocationBridge.locationUpdates.listen((location) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_lastLat = location['latitude']?.toStringAsFixed(4) ?? '--';
|
||||
_lastLon = location['longitude']?.toStringAsFixed(4) ?? '--';
|
||||
_lastLat = location['latitude']?.toStringAsFixed(5) ?? '--';
|
||||
_lastLon = location['longitude']?.toStringAsFixed(5) ?? '--';
|
||||
_lastSpeed = location['speed'] != null
|
||||
? '${(location['speed'] * 3.6).toStringAsFixed(0)} km/h'
|
||||
? (location['speed'] * 3.6).toStringAsFixed(1)
|
||||
: '--';
|
||||
_lastTime = location['timestamp'] != null
|
||||
? _formatTime(
|
||||
? _formatDateTime(
|
||||
DateTime.fromMillisecondsSinceEpoch(location['timestamp']),
|
||||
)
|
||||
: '--';
|
||||
|
|
@ -77,17 +88,16 @@ class _MainScreenState extends State<MainScreen> {
|
|||
});
|
||||
}
|
||||
|
||||
String _formatTime(DateTime dt) {
|
||||
return '${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}:${dt.second.toString().padLeft(2, '0')}';
|
||||
String _formatDateTime(DateTime dt) {
|
||||
return '${dt.year}-${dt.month.toString().padLeft(2, '0')}-${dt.day.toString().padLeft(2, '0')} '
|
||||
'${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}:${dt.second.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
Future<void> _toggleTracking() async {
|
||||
final previousState = _isTracking;
|
||||
final newState = !_isTracking;
|
||||
|
||||
setState(() {
|
||||
_isTracking = newState;
|
||||
});
|
||||
setState(() => _isTracking = newState);
|
||||
|
||||
bool success;
|
||||
if (newState) {
|
||||
|
|
@ -109,9 +119,7 @@ class _MainScreenState extends State<MainScreen> {
|
|||
}
|
||||
|
||||
if (!success && mounted) {
|
||||
setState(() {
|
||||
_isTracking = previousState;
|
||||
});
|
||||
setState(() => _isTracking = previousState);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
|
|
@ -119,75 +127,243 @@ class _MainScreenState extends State<MainScreen> {
|
|||
? 'Failed to stop tracking'
|
||||
: 'Failed to start tracking',
|
||||
),
|
||||
backgroundColor: const Color(0xFF1a1a1a),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── BUILD ────────────────────────────────────────────────────────────────
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Traccar Client'), centerTitle: true),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
backgroundColor: const Color(0xFF0d0d0d),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildStatusCard(),
|
||||
const SizedBox(height: 24),
|
||||
_buildTrackingToggle(),
|
||||
const Spacer(),
|
||||
_buildActionButtons(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusCard() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Last Location',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
_buildHeader(),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
_buildStatusCard(),
|
||||
const SizedBox(height: 16),
|
||||
_buildTrackingToggle(),
|
||||
const Spacer(),
|
||||
_buildActionButtons(),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildInfoRow('Lat', _lastLat),
|
||||
_buildInfoRow('Lon', _lastLon),
|
||||
_buildInfoRow('Speed', _lastSpeed),
|
||||
_buildInfoRow('Time', _lastTime),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFF161616),
|
||||
border: Border(bottom: BorderSide(color: Color(0xFF2a2a2a), width: 1)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label),
|
||||
Text(value, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _isTracking
|
||||
? const Color(0xFF00e676)
|
||||
: const Color(0xFF616161),
|
||||
boxShadow: _isTracking
|
||||
? [
|
||||
BoxShadow(
|
||||
color: const Color(0xFF00e676).withOpacity(0.6),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'TRACCAR CLIENT',
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 3,
|
||||
color: Color(0xFFe0e0e0),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
_isTracking ? 'ACTIVE' : 'IDLE',
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 2,
|
||||
color: _isTracking
|
||||
? const Color(0xFF00e676)
|
||||
: const Color(0xFF616161),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTrackingToggle() {
|
||||
return SwitchListTile(
|
||||
title: Text(_isTracking ? 'Tracking: ON' : 'Tracking: OFF'),
|
||||
subtitle: Text(
|
||||
_isTracking ? 'Location updates active' : 'Tap to start tracking',
|
||||
Widget _buildStatusCard() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF161616),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: const Color(0xFF2a2a2a), width: 1),
|
||||
),
|
||||
value: _isTracking,
|
||||
onChanged: (_) => _toggleTracking(),
|
||||
activeTrackColor: Colors.green,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.gps_fixed, size: 14, color: Color(0xFF00bcd4)),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'COORDINATES',
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 2,
|
||||
color: const Color(0xFF00bcd4).withOpacity(0.8),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildCoordRow('LAT', _lastLat, const Color(0xFF69f0ae)),
|
||||
const SizedBox(height: 10),
|
||||
_buildCoordRow('LON', _lastLon, const Color(0xFF69f0ae)),
|
||||
const SizedBox(height: 18),
|
||||
Container(height: 1, color: const Color(0xFF2a2a2a)),
|
||||
const SizedBox(height: 18),
|
||||
_buildCoordRow('SPD', _lastSpeed, const Color(0xFFff9800)),
|
||||
const SizedBox(height: 10),
|
||||
_buildCoordRow('TIM', _lastTime, const Color(0xFF9e9e9e)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCoordRow(String label, String value, Color valueColor) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 36,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 1,
|
||||
color: Color(0xFF616161),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
letterSpacing: 1,
|
||||
color: valueColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTrackingToggle() {
|
||||
return AnimatedBuilder(
|
||||
animation: _pulseAnimation,
|
||||
builder: (context, child) {
|
||||
return GestureDetector(
|
||||
onTap: _toggleTracking,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 20),
|
||||
decoration: BoxDecoration(
|
||||
color: _isTracking
|
||||
? Color.lerp(
|
||||
const Color(0xFF1b5e20),
|
||||
const Color(0xFF2e7d32),
|
||||
_pulseAnimation.value,
|
||||
)
|
||||
: const Color(0xFF1a1a1a),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(
|
||||
color: _isTracking
|
||||
? const Color(0xFF00e676)
|
||||
: const Color(0xFF2a2a2a),
|
||||
width: 1.5,
|
||||
),
|
||||
boxShadow: _isTracking
|
||||
? [
|
||||
BoxShadow(
|
||||
color: const Color(
|
||||
0xFF00e676,
|
||||
).withOpacity(0.15 * _pulseAnimation.value),
|
||||
blurRadius: 12,
|
||||
spreadRadius: 0,
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
_isTracking
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_off,
|
||||
color: _isTracking
|
||||
? const Color(0xFF00e676)
|
||||
: const Color(0xFF616161),
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
_isTracking ? 'TRACKING ACTIVE' : 'START TRACKING',
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 2,
|
||||
color: _isTracking
|
||||
? const Color(0xFF00e676)
|
||||
: const Color(0xFF9e9e9e),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -196,10 +372,11 @@ class _MainScreenState extends State<MainScreen> {
|
|||
children: [
|
||||
if (_isTracking)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
height: 44,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () async {
|
||||
final success = await LocationBridge.reportLocation();
|
||||
if (mounted) {
|
||||
|
|
@ -208,43 +385,53 @@ class _MainScreenState extends State<MainScreen> {
|
|||
content: Text(
|
||||
success
|
||||
? 'Location sent to server'
|
||||
: 'Failed - check logs',
|
||||
: 'Failed — check logs',
|
||||
),
|
||||
duration: Duration(seconds: 2),
|
||||
backgroundColor: const Color(0xFF1a1a1a),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.send),
|
||||
label: const Text('Send Location'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFF00bcd4),
|
||||
side: const BorderSide(color: Color(0xFF00bcd4), width: 1),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
icon: const Icon(Icons.arrow_upward, size: 16),
|
||||
label: const Text(
|
||||
'SEND LOCATION',
|
||||
style: TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
letterSpacing: 1,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const SettingsScreen()),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.settings),
|
||||
label: const Text('Settings'),
|
||||
child: _buildNavButton(
|
||||
icon: Icons.tune,
|
||||
label: 'SETTINGS',
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const SettingsScreen()),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const StatusScreen()),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.history),
|
||||
label: const Text('Status/Logs'),
|
||||
child: _buildNavButton(
|
||||
icon: Icons.terminal,
|
||||
label: 'LOGS',
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const StatusScreen()),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
@ -252,4 +439,43 @@ class _MainScreenState extends State<MainScreen> {
|
|||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavButton({
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Material(
|
||||
color: const Color(0xFF161616),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: const Color(0xFF2a2a2a), width: 1),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 16, color: const Color(0xFF757575)),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'monospace',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 2,
|
||||
color: Color(0xFF9e9e9e),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue