mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-10-09 19:55:05 +00:00
chore: Initial commit
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPovRHpejR4zRxuhjY4Qs3
This commit is contained in:
175
lib/widgets/common/bidirectional_refresh.dart
Normal file
175
lib/widgets/common/bidirectional_refresh.dart
Normal file
@@ -0,0 +1,175 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
enum _RefreshEdge { top, bottom }
|
||||
|
||||
class BidirectionalRefresh extends StatefulWidget {
|
||||
static const double defaultTriggerDistance = 90;
|
||||
|
||||
final Widget child;
|
||||
final Future<void> Function() onRefresh;
|
||||
final double triggerDistance;
|
||||
|
||||
const BidirectionalRefresh({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.onRefresh,
|
||||
this.triggerDistance = defaultTriggerDistance,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BidirectionalRefresh> createState() => _BidirectionalRefreshState();
|
||||
}
|
||||
|
||||
class _BidirectionalRefreshState extends State<BidirectionalRefresh> {
|
||||
double _topPullDistance = 0;
|
||||
double _bottomPullDistance = 0;
|
||||
bool _isRefreshing = false;
|
||||
|
||||
bool _handleScrollNotification(ScrollNotification notification) {
|
||||
if (_isRefreshing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (notification is ScrollStartNotification) {
|
||||
_resetPullDistance();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (notification is OverscrollNotification) {
|
||||
final metrics = notification.metrics;
|
||||
final isAtTop = metrics.extentBefore == 0;
|
||||
final isAtBottom = metrics.extentAfter == 0;
|
||||
|
||||
if (!isAtTop && !isAtBottom) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var shouldRefresh = false;
|
||||
setState(() {
|
||||
if (isAtTop) {
|
||||
_topPullDistance += notification.overscroll.abs();
|
||||
shouldRefresh = _topPullDistance >= widget.triggerDistance;
|
||||
}
|
||||
if (isAtBottom) {
|
||||
_bottomPullDistance += notification.overscroll.abs();
|
||||
shouldRefresh =
|
||||
shouldRefresh || _bottomPullDistance >= widget.triggerDistance;
|
||||
}
|
||||
});
|
||||
if (shouldRefresh) {
|
||||
_runRefresh();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (notification is ScrollEndNotification) {
|
||||
_resetPullDistance();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> _runRefresh() async {
|
||||
if (_isRefreshing) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isRefreshing = true;
|
||||
});
|
||||
|
||||
try {
|
||||
await widget.onRefresh();
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isRefreshing = false;
|
||||
_topPullDistance = 0;
|
||||
_bottomPullDistance = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _resetPullDistance() {
|
||||
if (_topPullDistance == 0 && _bottomPullDistance == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_topPullDistance = 0;
|
||||
_bottomPullDistance = 0;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final topProgress = (_topPullDistance / widget.triggerDistance).clamp(
|
||||
0.0,
|
||||
1.0,
|
||||
);
|
||||
final bottomProgress = (_bottomPullDistance / widget.triggerDistance).clamp(
|
||||
0.0,
|
||||
1.0,
|
||||
);
|
||||
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: _handleScrollNotification,
|
||||
child: Stack(
|
||||
children: [
|
||||
widget.child,
|
||||
_RefreshIndicatorOverlay(
|
||||
alignment: Alignment.topCenter,
|
||||
progress: _isRefreshing ? 1 : topProgress,
|
||||
visible: _isRefreshing || _topPullDistance > 0,
|
||||
edge: _RefreshEdge.top,
|
||||
),
|
||||
_RefreshIndicatorOverlay(
|
||||
alignment: Alignment.bottomCenter,
|
||||
progress: _isRefreshing ? 1 : bottomProgress,
|
||||
visible: _isRefreshing || _bottomPullDistance > 0,
|
||||
edge: _RefreshEdge.bottom,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RefreshIndicatorOverlay extends StatelessWidget {
|
||||
final Alignment alignment;
|
||||
final double progress;
|
||||
final bool visible;
|
||||
final _RefreshEdge edge;
|
||||
|
||||
const _RefreshIndicatorOverlay({
|
||||
required this.alignment,
|
||||
required this.progress,
|
||||
required this.visible,
|
||||
required this.edge,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!visible) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final indicator = RefreshProgressIndicator(value: progress);
|
||||
final padding = edge == _RefreshEdge.top
|
||||
? const EdgeInsets.only(top: 12)
|
||||
: const EdgeInsets.only(bottom: 12);
|
||||
|
||||
return Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: Align(
|
||||
alignment: alignment,
|
||||
child: Padding(
|
||||
padding: padding,
|
||||
child: SizedBox.square(dimension: 28, child: indicator),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
141
lib/widgets/common/contact_avatar.dart
Normal file
141
lib/widgets/common/contact_avatar.dart
Normal file
@@ -0,0 +1,141 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../models/contact.dart';
|
||||
import '../../services/trail_color_service.dart';
|
||||
import '../../utils/avatar_label_helper.dart';
|
||||
|
||||
class ContactAvatar extends StatelessWidget {
|
||||
final Contact contact;
|
||||
final double radius;
|
||||
final String? displayName;
|
||||
|
||||
const ContactAvatar({
|
||||
super.key,
|
||||
required this.contact,
|
||||
this.radius = 20,
|
||||
this.displayName,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backgroundColor = _getBackgroundColor(context);
|
||||
final foregroundColor = _getForegroundColor(backgroundColor);
|
||||
final emoji = contact.roleEmoji;
|
||||
|
||||
if (_showsLeadingEmoji && emoji != null && emoji.isNotEmpty) {
|
||||
return _buildAvatarFrame(
|
||||
backgroundColor: backgroundColor,
|
||||
child: Text(emoji, style: TextStyle(fontSize: radius * 1.05)),
|
||||
);
|
||||
}
|
||||
|
||||
if (_shouldUseLabelFallback) {
|
||||
return _buildAvatarFrame(
|
||||
backgroundColor: backgroundColor,
|
||||
child: Text(
|
||||
AvatarLabelHelper.buildLabel(displayName ?? contact.displayName),
|
||||
style: TextStyle(
|
||||
color: foregroundColor,
|
||||
fontSize: radius * 0.68,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: -0.4,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return _buildAvatarFrame(
|
||||
backgroundColor: backgroundColor,
|
||||
child: Icon(
|
||||
_getTypeIcon(contact.type),
|
||||
color: foregroundColor,
|
||||
size: radius,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAvatarFrame({
|
||||
required Color backgroundColor,
|
||||
required Widget child,
|
||||
}) {
|
||||
if (_usesSquareShape) {
|
||||
return Container(
|
||||
width: radius * 2,
|
||||
height: radius * 2,
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor,
|
||||
borderRadius: BorderRadius.circular(radius * 0.6),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
return CircleAvatar(
|
||||
radius: radius,
|
||||
backgroundColor: backgroundColor,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
bool get _shouldUseLabelFallback =>
|
||||
contact.type == ContactType.chat ||
|
||||
contact.type == ContactType.channel ||
|
||||
contact.type == ContactType.room;
|
||||
|
||||
bool get _usesSquareShape =>
|
||||
contact.type == ContactType.channel || contact.type == ContactType.room;
|
||||
|
||||
bool get _showsLeadingEmoji {
|
||||
final emoji = contact.roleEmoji;
|
||||
if (emoji == null || emoji.isEmpty) return false;
|
||||
|
||||
final effectiveName = (displayName ?? contact.displayName).trimLeft();
|
||||
return effectiveName.startsWith(emoji);
|
||||
}
|
||||
|
||||
Color _getBackgroundColor(BuildContext context) {
|
||||
if (_shouldUseLabelFallback || _showsLeadingEmoji) {
|
||||
return TrailColorService.getTrailColor(contact);
|
||||
}
|
||||
|
||||
switch (contact.type) {
|
||||
case ContactType.none:
|
||||
return Theme.of(context).colorScheme.surfaceContainerHighest;
|
||||
case ContactType.chat:
|
||||
return Colors.blue;
|
||||
case ContactType.repeater:
|
||||
return Colors.orange;
|
||||
case ContactType.room:
|
||||
return Colors.purple;
|
||||
case ContactType.sensor:
|
||||
return Colors.green;
|
||||
case ContactType.channel:
|
||||
return Colors.teal;
|
||||
}
|
||||
}
|
||||
|
||||
Color _getForegroundColor(Color backgroundColor) {
|
||||
return ThemeData.estimateBrightnessForColor(backgroundColor) ==
|
||||
Brightness.dark
|
||||
? Colors.white
|
||||
: Colors.black87;
|
||||
}
|
||||
|
||||
IconData _getTypeIcon(ContactType type) {
|
||||
switch (type) {
|
||||
case ContactType.none:
|
||||
return Icons.help_outline;
|
||||
case ContactType.chat:
|
||||
return Icons.person;
|
||||
case ContactType.repeater:
|
||||
return Icons.router;
|
||||
case ContactType.room:
|
||||
return Icons.meeting_room;
|
||||
case ContactType.sensor:
|
||||
return Icons.sensors;
|
||||
case ContactType.channel:
|
||||
return Icons.public;
|
||||
}
|
||||
}
|
||||
}
|
||||
245
lib/widgets/common/location_display.dart
Normal file
245
lib/widgets/common/location_display.dart
Normal file
@@ -0,0 +1,245 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../../utils/location_formats.dart';
|
||||
|
||||
/// Reusable location display widget with tap-to-show modal
|
||||
/// Shows coordinates in a compact format with ability to view all formats
|
||||
class LocationDisplay extends StatelessWidget {
|
||||
final LatLng location;
|
||||
final bool compact;
|
||||
|
||||
const LocationDisplay({
|
||||
super.key,
|
||||
required this.location,
|
||||
this.compact = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (compact) {
|
||||
return GestureDetector(
|
||||
onTap: () => _showLocationFormats(context),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.location_on, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${location.latitude.toStringAsFixed(5)}, ${location.longitude.toStringAsFixed(5)}',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontFamily: 'monospace',
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
Icons.open_in_new,
|
||||
size: 14,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Non-compact version (just text)
|
||||
return Text(
|
||||
'${location.latitude.toStringAsFixed(5)}, ${location.longitude.toStringAsFixed(5)}',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodyMedium?.copyWith(fontFamily: 'monospace'),
|
||||
);
|
||||
}
|
||||
|
||||
void _showLocationFormats(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
builder: (context) => SingleChildScrollView(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Location Formats',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Divider(),
|
||||
const SizedBox(height: 8),
|
||||
// Decimal Degrees (DD)
|
||||
_buildFormatRow(
|
||||
context,
|
||||
'DD (Decimal Degrees)',
|
||||
'${location.latitude.toStringAsFixed(6)}, ${location.longitude.toStringAsFixed(6)}',
|
||||
),
|
||||
// Degrees Minutes Seconds (DMS)
|
||||
_buildFormatRow(
|
||||
context,
|
||||
'DMS (Degrees Minutes Seconds)',
|
||||
_convertToDMS(location.latitude, location.longitude),
|
||||
),
|
||||
// Degrees Decimal Minutes (DDM)
|
||||
_buildFormatRow(
|
||||
context,
|
||||
'DDM (Degrees Decimal Minutes)',
|
||||
_convertToDDM(location.latitude, location.longitude),
|
||||
),
|
||||
// MGRS (Military Grid Reference System)
|
||||
_buildFormatRow(
|
||||
context,
|
||||
'MGRS (Military Grid)',
|
||||
_convertToMGRS(location.latitude, location.longitude),
|
||||
),
|
||||
// Google Plus Code
|
||||
_buildFormatRow(
|
||||
context,
|
||||
'Plus Code',
|
||||
formatPlusCode(location.latitude, location.longitude),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFormatRow(BuildContext context, String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: Colors.grey,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Clipboard.setData(ClipboardData(text: value));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
AppLocalizations.of(context)!.copiedToClipboard(label),
|
||||
),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontFamily: 'monospace',
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.copy,
|
||||
size: 18,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert to Degrees Minutes Seconds (DMS) format
|
||||
String _convertToDMS(double lat, double lon) {
|
||||
String latDir = lat >= 0 ? 'N' : 'S';
|
||||
String lonDir = lon >= 0 ? 'E' : 'W';
|
||||
|
||||
lat = lat.abs();
|
||||
lon = lon.abs();
|
||||
|
||||
int latDeg = lat.floor();
|
||||
double latMinDec = (lat - latDeg) * 60;
|
||||
int latMin = latMinDec.floor();
|
||||
double latSec = (latMinDec - latMin) * 60;
|
||||
|
||||
int lonDeg = lon.floor();
|
||||
double lonMinDec = (lon - lonDeg) * 60;
|
||||
int lonMin = lonMinDec.floor();
|
||||
double lonSec = (lonMinDec - lonMin) * 60;
|
||||
|
||||
return '$latDeg°$latMin\'${latSec.toStringAsFixed(2)}"$latDir, $lonDeg°$lonMin\'${lonSec.toStringAsFixed(2)}"$lonDir';
|
||||
}
|
||||
|
||||
/// Convert to Degrees Decimal Minutes (DDM) format
|
||||
String _convertToDDM(double lat, double lon) {
|
||||
String latDir = lat >= 0 ? 'N' : 'S';
|
||||
String lonDir = lon >= 0 ? 'E' : 'W';
|
||||
|
||||
lat = lat.abs();
|
||||
lon = lon.abs();
|
||||
|
||||
int latDeg = lat.floor();
|
||||
double latMin = (lat - latDeg) * 60;
|
||||
|
||||
int lonDeg = lon.floor();
|
||||
double lonMin = (lon - lonDeg) * 60;
|
||||
|
||||
return '$latDeg° ${latMin.toStringAsFixed(4)}\'$latDir, $lonDeg° ${lonMin.toStringAsFixed(4)}\'$lonDir';
|
||||
}
|
||||
|
||||
/// Convert to MGRS (Military Grid Reference System) format
|
||||
/// Simplified implementation - returns approximate grid zone
|
||||
String _convertToMGRS(double lat, double lon) {
|
||||
// Zone number (1-60)
|
||||
int zone = ((lon + 180) / 6).floor() + 1;
|
||||
|
||||
// Zone letter (C-X, excluding I and O)
|
||||
const letters = 'CDEFGHJKLMNPQRSTUVWX';
|
||||
int letterIndex = ((lat + 80) / 8).floor();
|
||||
if (letterIndex < 0) letterIndex = 0;
|
||||
if (letterIndex >= letters.length) letterIndex = letters.length - 1;
|
||||
String letter = letters[letterIndex];
|
||||
|
||||
// Simplified - just show zone designation
|
||||
// Full MGRS would require UTM conversion library
|
||||
return '$zone$letter (approximate)';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user