mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: Enhance drawing functionality with sender tracking and sharing capabilities
This commit is contained in:
Binary file not shown.
BIN
ios/Runner.ipa
BIN
ios/Runner.ipa
Binary file not shown.
@@ -5,22 +5,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000218">
|
<testcase classname="fastlane.lanes" name="0: default_platform" time="0.000202">
|
||||||
|
|
||||||
</testcase>
|
</testcase>
|
||||||
|
|
||||||
|
|
||||||
<testcase classname="fastlane.lanes" name="1: increment_build_number" time="0.291087">
|
<testcase classname="fastlane.lanes" name="1: increment_build_number" time="0.672147">
|
||||||
|
|
||||||
</testcase>
|
</testcase>
|
||||||
|
|
||||||
|
|
||||||
<testcase classname="fastlane.lanes" name="2: build_app" time="87.202089">
|
<testcase classname="fastlane.lanes" name="2: build_app" time="92.816744">
|
||||||
|
|
||||||
</testcase>
|
</testcase>
|
||||||
|
|
||||||
|
|
||||||
<testcase classname="fastlane.lanes" name="3: upload_to_testflight" time="12.706053">
|
<testcase classname="fastlane.lanes" name="3: upload_to_testflight" time="14.725453">
|
||||||
|
|
||||||
<failure message="/opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/actions/actions_helper.rb:67:in 'Fastlane::Actions.execute_action' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:255:in 'block in Fastlane::Runner#execute_action' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:229:in 'Dir.chdir' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:229:in 'Fastlane::Runner#execute_action' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:157:in 'Fastlane::Runner#trigger_action_by_name' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/fast_file.rb:159:in 'Fastlane::FastFile#method_missing' Fastfile:23:in 'block (2 levels) in Fastlane::FastFile#parsing_binding' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/lane.rb:41:in 'Fastlane::Lane#call' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:49:in 'block in Fastlane::Runner#execute' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:45:in 'Dir.chdir' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:45:in 'Fastlane::Runner#execute' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/lane_manager.rb:46:in 'Fastlane::LaneManager.cruise_lane' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/command_line_handler.rb:34:in 'Fastlane::CommandLineHandler.handle' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/commands_generator.rb:110:in 'block (2 levels) in Fastlane::CommandsGenerator#run' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/command.rb:187:in 'Commander::Command#call' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/command.rb:157:in 'Commander::Command#run' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/runner.rb:444:in 'Commander::Runner#run_active_command' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:124:in 'Commander::Runner#run!' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/delegates.rb:18:in 'Commander::Delegates#run!' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/commands_generator.rb:363:in 'Fastlane::CommandsGenerator#run' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/commands_generator.rb:43:in 'Fastlane::CommandsGenerator.start' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/cli_tools_distributor.rb:123:in 'Fastlane::CLIToolsDistributor.take_off' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/bin/fastlane:23:in '<top (required)>' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/bin/fastlane:25:in 'Kernel#load' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/bin/fastlane:25:in '<main>' Error uploading ipa file: [Application Loader Error Output]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure." />
|
<failure message="/opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/actions/actions_helper.rb:67:in 'Fastlane::Actions.execute_action' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:255:in 'block in Fastlane::Runner#execute_action' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:229:in 'Dir.chdir' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:229:in 'Fastlane::Runner#execute_action' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:157:in 'Fastlane::Runner#trigger_action_by_name' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/fast_file.rb:159:in 'Fastlane::FastFile#method_missing' Fastfile:23:in 'block (2 levels) in Fastlane::FastFile#parsing_binding' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/lane.rb:41:in 'Fastlane::Lane#call' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:49:in 'block in Fastlane::Runner#execute' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:45:in 'Dir.chdir' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/runner.rb:45:in 'Fastlane::Runner#execute' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/lane_manager.rb:46:in 'Fastlane::LaneManager.cruise_lane' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/command_line_handler.rb:34:in 'Fastlane::CommandLineHandler.handle' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/commands_generator.rb:110:in 'block (2 levels) in Fastlane::CommandsGenerator#run' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/command.rb:187:in 'Commander::Command#call' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/command.rb:157:in 'Commander::Command#run' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/runner.rb:444:in 'Commander::Runner#run_active_command' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:124:in 'Commander::Runner#run!' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/commander-4.6.0/lib/commander/delegates.rb:18:in 'Commander::Delegates#run!' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/commands_generator.rb:363:in 'Fastlane::CommandsGenerator#run' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/commands_generator.rb:43:in 'Fastlane::CommandsGenerator.start' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/fastlane/lib/fastlane/cli_tools_distributor.rb:123:in 'Fastlane::CLIToolsDistributor.take_off' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/gems/fastlane-2.228.0/bin/fastlane:23:in '<top (required)>' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/bin/fastlane:25:in 'Kernel#load' /opt/homebrew/Cellar/fastlane/2.228.0/libexec/bin/fastlane:25:in '<main>' Error uploading ipa file: [Application Loader Error Output]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure." />
|
||||||
|
|
||||||
|
|||||||
@@ -98,20 +98,22 @@ class _MeshCoreSarAppState extends State<MeshCoreSarApp> {
|
|||||||
Provider(create: (_) => TileCacheService()),
|
Provider(create: (_) => TileCacheService()),
|
||||||
|
|
||||||
// App provider that coordinates everything
|
// App provider that coordinates everything
|
||||||
ChangeNotifierProxyProvider4<ConnectionProvider, ContactsProvider,
|
ChangeNotifierProxyProvider5<ConnectionProvider, ContactsProvider,
|
||||||
MessagesProvider, TileCacheService, AppProvider>(
|
MessagesProvider, DrawingProvider, TileCacheService, AppProvider>(
|
||||||
create: (context) => AppProvider(
|
create: (context) => AppProvider(
|
||||||
connectionProvider: context.read<ConnectionProvider>(),
|
connectionProvider: context.read<ConnectionProvider>(),
|
||||||
contactsProvider: context.read<ContactsProvider>(),
|
contactsProvider: context.read<ContactsProvider>(),
|
||||||
messagesProvider: context.read<MessagesProvider>(),
|
messagesProvider: context.read<MessagesProvider>(),
|
||||||
|
drawingProvider: context.read<DrawingProvider>(),
|
||||||
tileCacheService: context.read<TileCacheService>(),
|
tileCacheService: context.read<TileCacheService>(),
|
||||||
),
|
),
|
||||||
update: (context, conn, contacts, messages, tileCache, previous) =>
|
update: (context, conn, contacts, messages, drawings, tileCache, previous) =>
|
||||||
previous ??
|
previous ??
|
||||||
AppProvider(
|
AppProvider(
|
||||||
connectionProvider: conn,
|
connectionProvider: conn,
|
||||||
contactsProvider: contacts,
|
contactsProvider: contacts,
|
||||||
messagesProvider: messages,
|
messagesProvider: messages,
|
||||||
|
drawingProvider: drawings,
|
||||||
tileCacheService: tileCache,
|
tileCacheService: tileCache,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -39,17 +39,28 @@ abstract class MapDrawing {
|
|||||||
final DrawingShapeType type;
|
final DrawingShapeType type;
|
||||||
final Color color;
|
final Color color;
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
|
final String? senderName; // Name of sender (null if local drawing)
|
||||||
|
final bool isReceived; // True if drawing was received from another node
|
||||||
|
|
||||||
MapDrawing({
|
MapDrawing({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.type,
|
required this.type,
|
||||||
required this.color,
|
required this.color,
|
||||||
required this.createdAt,
|
required this.createdAt,
|
||||||
|
this.senderName,
|
||||||
|
this.isReceived = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Convert to JSON for persistence
|
/// Convert to JSON for persistence
|
||||||
Map<String, dynamic> toJson();
|
Map<String, dynamic> toJson();
|
||||||
|
|
||||||
|
/// Convert to JSON for network transmission (includes sender name)
|
||||||
|
Map<String, dynamic> toNetworkJson(String senderName) {
|
||||||
|
final json = toJson();
|
||||||
|
json['sender'] = senderName;
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
/// Create from JSON
|
/// Create from JSON
|
||||||
static MapDrawing? fromJson(Map<String, dynamic> json) {
|
static MapDrawing? fromJson(Map<String, dynamic> json) {
|
||||||
final typeStr = json['type'] as String?;
|
final typeStr = json['type'] as String?;
|
||||||
@@ -81,6 +92,8 @@ class LineDrawing extends MapDrawing {
|
|||||||
required super.color,
|
required super.color,
|
||||||
required super.createdAt,
|
required super.createdAt,
|
||||||
required this.points,
|
required this.points,
|
||||||
|
super.senderName,
|
||||||
|
super.isReceived,
|
||||||
}) : super(type: DrawingShapeType.line);
|
}) : super(type: DrawingShapeType.line);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -97,12 +110,15 @@ class LineDrawing extends MapDrawing {
|
|||||||
static LineDrawing fromJson(Map<String, dynamic> json) {
|
static LineDrawing fromJson(Map<String, dynamic> json) {
|
||||||
final pointsJson = json['points'] as List<dynamic>;
|
final pointsJson = json['points'] as List<dynamic>;
|
||||||
final points = pointsJson.map((p) => LatLng(p['lat'] as double, p['lon'] as double)).toList();
|
final points = pointsJson.map((p) => LatLng(p['lat'] as double, p['lon'] as double)).toList();
|
||||||
|
final senderName = json['sender'] as String?;
|
||||||
|
|
||||||
return LineDrawing(
|
return LineDrawing(
|
||||||
id: json['id'] as String,
|
id: json['id'] as String,
|
||||||
color: Color(json['color'] as int),
|
color: Color(json['color'] as int),
|
||||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||||
points: points,
|
points: points,
|
||||||
|
senderName: senderName,
|
||||||
|
isReceived: senderName != null, // Mark as received if sender is present
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +144,8 @@ class RectangleDrawing extends MapDrawing {
|
|||||||
required super.createdAt,
|
required super.createdAt,
|
||||||
required this.topLeft,
|
required this.topLeft,
|
||||||
required this.bottomRight,
|
required this.bottomRight,
|
||||||
|
super.senderName,
|
||||||
|
super.isReceived,
|
||||||
}) : super(type: DrawingShapeType.rectangle);
|
}) : super(type: DrawingShapeType.rectangle);
|
||||||
|
|
||||||
/// Get all corner points for rendering
|
/// Get all corner points for rendering
|
||||||
@@ -154,6 +172,7 @@ class RectangleDrawing extends MapDrawing {
|
|||||||
static RectangleDrawing fromJson(Map<String, dynamic> json) {
|
static RectangleDrawing fromJson(Map<String, dynamic> json) {
|
||||||
final topLeftJson = json['topLeft'] as Map<String, dynamic>;
|
final topLeftJson = json['topLeft'] as Map<String, dynamic>;
|
||||||
final bottomRightJson = json['bottomRight'] as Map<String, dynamic>;
|
final bottomRightJson = json['bottomRight'] as Map<String, dynamic>;
|
||||||
|
final senderName = json['sender'] as String?;
|
||||||
|
|
||||||
return RectangleDrawing(
|
return RectangleDrawing(
|
||||||
id: json['id'] as String,
|
id: json['id'] as String,
|
||||||
@@ -161,6 +180,8 @@ class RectangleDrawing extends MapDrawing {
|
|||||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||||
topLeft: LatLng(topLeftJson['lat'] as double, topLeftJson['lon'] as double),
|
topLeft: LatLng(topLeftJson['lat'] as double, topLeftJson['lon'] as double),
|
||||||
bottomRight: LatLng(bottomRightJson['lat'] as double, bottomRightJson['lon'] as double),
|
bottomRight: LatLng(bottomRightJson['lat'] as double, bottomRightJson['lon'] as double),
|
||||||
|
senderName: senderName,
|
||||||
|
isReceived: senderName != null, // Mark as received if sender is present
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,17 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'connection_provider.dart';
|
import 'connection_provider.dart';
|
||||||
import 'contacts_provider.dart';
|
import 'contacts_provider.dart';
|
||||||
import 'messages_provider.dart';
|
import 'messages_provider.dart';
|
||||||
|
import 'drawing_provider.dart';
|
||||||
import '../services/tile_cache_service.dart';
|
import '../services/tile_cache_service.dart';
|
||||||
import '../models/contact.dart';
|
import '../models/contact.dart';
|
||||||
|
import '../utils/drawing_message_parser.dart';
|
||||||
|
|
||||||
/// Main App Provider - coordinates all other providers
|
/// Main App Provider - coordinates all other providers
|
||||||
class AppProvider with ChangeNotifier {
|
class AppProvider with ChangeNotifier {
|
||||||
final ConnectionProvider connectionProvider;
|
final ConnectionProvider connectionProvider;
|
||||||
final ContactsProvider contactsProvider;
|
final ContactsProvider contactsProvider;
|
||||||
final MessagesProvider messagesProvider;
|
final MessagesProvider messagesProvider;
|
||||||
|
final DrawingProvider drawingProvider;
|
||||||
final TileCacheService tileCacheService;
|
final TileCacheService tileCacheService;
|
||||||
|
|
||||||
bool _isInitialized = false;
|
bool _isInitialized = false;
|
||||||
@@ -21,6 +24,7 @@ class AppProvider with ChangeNotifier {
|
|||||||
required this.connectionProvider,
|
required this.connectionProvider,
|
||||||
required this.contactsProvider,
|
required this.contactsProvider,
|
||||||
required this.messagesProvider,
|
required this.messagesProvider,
|
||||||
|
required this.drawingProvider,
|
||||||
required this.tileCacheService,
|
required this.tileCacheService,
|
||||||
}) {
|
}) {
|
||||||
_setupCallbacks();
|
_setupCallbacks();
|
||||||
@@ -61,6 +65,20 @@ class AppProvider with ChangeNotifier {
|
|||||||
|
|
||||||
// When a message is received
|
// When a message is received
|
||||||
connectionProvider.onMessageReceived = (message) {
|
connectionProvider.onMessageReceived = (message) {
|
||||||
|
// Check if message is a drawing broadcast
|
||||||
|
if (DrawingMessageParser.isDrawingMessage(message.text)) {
|
||||||
|
debugPrint('🎨 [AppProvider] Drawing message received, parsing...');
|
||||||
|
final drawing = DrawingMessageParser.parseDrawingMessage(message.text);
|
||||||
|
if (drawing != null) {
|
||||||
|
debugPrint('🎨 [AppProvider] Drawing parsed successfully: ${drawing.type.name} from ${drawing.senderName ?? "unknown"}');
|
||||||
|
drawingProvider.addReceivedDrawing(drawing);
|
||||||
|
} else {
|
||||||
|
debugPrint('⚠️ [AppProvider] Failed to parse drawing message');
|
||||||
|
}
|
||||||
|
// Don't add drawing messages to the message list
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Pass contact lookup function to link channel messages with contacts
|
// Pass contact lookup function to link channel messages with contacts
|
||||||
messagesProvider.addMessage(
|
messagesProvider.addMessage(
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:latlong2/latlong.dart';
|
import 'package:latlong2/latlong.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import '../models/map_drawing.dart';
|
import '../models/map_drawing.dart';
|
||||||
|
import '../utils/drawing_message_parser.dart';
|
||||||
|
|
||||||
/// Drawing mode state
|
/// Drawing mode state
|
||||||
enum DrawingMode {
|
enum DrawingMode {
|
||||||
@@ -255,4 +257,23 @@ class DrawingProvider with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add received drawing from another node
|
||||||
|
void addReceivedDrawing(MapDrawing drawing) {
|
||||||
|
// Check if drawing with this ID already exists
|
||||||
|
if (_drawings.any((d) => d.id == drawing.id)) {
|
||||||
|
debugPrint('Drawing ${drawing.id} already exists, skipping');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawings.add(drawing);
|
||||||
|
_saveDrawings();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Broadcast a drawing to contacts
|
||||||
|
/// Returns the formatted message string ready to send
|
||||||
|
String createDrawingBroadcastMessage(MapDrawing drawing, String senderName) {
|
||||||
|
return DrawingMessageParser.createDrawingMessage(drawing, senderName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1172,50 +1172,53 @@ class _MapTabState extends State<MapTab> with AutomaticKeepAliveClientMixin {
|
|||||||
children: [
|
children: [
|
||||||
// Drawing toolbar
|
// Drawing toolbar
|
||||||
const DrawingToolbar(),
|
const DrawingToolbar(),
|
||||||
const SizedBox(height: 8),
|
// Hide other buttons when in drawing mode
|
||||||
FloatingActionButton.small(
|
if (!drawingProvider.isDrawing) ...[
|
||||||
heroTag: 'center_map',
|
const SizedBox(height: 8),
|
||||||
onPressed: !_isMapReady ? null : () async {
|
FloatingActionButton.small(
|
||||||
// Force update GPS location and jump to it
|
heroTag: 'center_map',
|
||||||
final position = await _locationService.getCurrentPosition();
|
onPressed: !_isMapReady ? null : () async {
|
||||||
if (position != null && mounted) {
|
// Force update GPS location and jump to it
|
||||||
setState(() {
|
final position = await _locationService.getCurrentPosition();
|
||||||
// Position updated in service
|
if (position != null && mounted) {
|
||||||
});
|
setState(() {
|
||||||
_mapController.move(
|
// Position updated in service
|
||||||
LatLng(position.latitude, position.longitude),
|
});
|
||||||
16,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// Fallback to cached position or default center
|
|
||||||
final currentPosition = _locationService.currentPosition;
|
|
||||||
if (currentPosition != null) {
|
|
||||||
_mapController.move(
|
_mapController.move(
|
||||||
LatLng(
|
LatLng(position.latitude, position.longitude),
|
||||||
currentPosition.latitude,
|
|
||||||
currentPosition.longitude,
|
|
||||||
),
|
|
||||||
16,
|
16,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
_mapController.move(center, _defaultZoom);
|
// Fallback to cached position or default center
|
||||||
|
final currentPosition = _locationService.currentPosition;
|
||||||
|
if (currentPosition != null) {
|
||||||
|
_mapController.move(
|
||||||
|
LatLng(
|
||||||
|
currentPosition.latitude,
|
||||||
|
currentPosition.longitude,
|
||||||
|
),
|
||||||
|
16,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
_mapController.move(center, _defaultZoom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
child: const Icon(Icons.my_location),
|
||||||
child: const Icon(Icons.my_location),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
FloatingActionButton.small(
|
|
||||||
heroTag: 'layer_selector',
|
|
||||||
onPressed: () => _showLayerSelector(context),
|
|
||||||
child: const Icon(Icons.layers),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
FloatingActionButton.small(
|
|
||||||
heroTag: 'options_menu',
|
|
||||||
onPressed: () => _showOptionsMenu(context),
|
|
||||||
child: const Icon(Icons.more_vert),
|
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
FloatingActionButton.small(
|
||||||
|
heroTag: 'layer_selector',
|
||||||
|
onPressed: () => _showLayerSelector(context),
|
||||||
|
child: const Icon(Icons.layers),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
FloatingActionButton.small(
|
||||||
|
heroTag: 'options_menu',
|
||||||
|
onPressed: () => _showOptionsMenu(context),
|
||||||
|
child: const Icon(Icons.more_vert),
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import '../providers/connection_provider.dart';
|
|||||||
import '../models/message.dart';
|
import '../models/message.dart';
|
||||||
import '../models/sar_marker.dart';
|
import '../models/sar_marker.dart';
|
||||||
import '../widgets/messages/sar_update_sheet.dart';
|
import '../widgets/messages/sar_update_sheet.dart';
|
||||||
|
import '../widgets/contacts/direct_message_sheet.dart';
|
||||||
import '../utils/toast_logger.dart';
|
import '../utils/toast_logger.dart';
|
||||||
|
|
||||||
class MessagesTab extends StatefulWidget {
|
class MessagesTab extends StatefulWidget {
|
||||||
@@ -507,6 +508,16 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showMessageOptions(BuildContext context) {
|
void _showMessageOptions(BuildContext context) {
|
||||||
|
// Determine if this is own message
|
||||||
|
final connectionProvider = context.read<ConnectionProvider>();
|
||||||
|
final selfPublicKey = connectionProvider.deviceInfo.publicKey;
|
||||||
|
final isOwnMessage = message.isSentMessage || message.isFromSelf(selfPublicKey);
|
||||||
|
|
||||||
|
// Check if we can reply to this message (must be contact message from someone else)
|
||||||
|
final canReply = message.isContactMessage &&
|
||||||
|
!isOwnMessage &&
|
||||||
|
message.senderPublicKeyPrefix != null;
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||||
@@ -518,6 +529,16 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
// Reply option (only for contact messages from others)
|
||||||
|
if (canReply)
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.reply),
|
||||||
|
title: const Text('Reply'),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
_showReplySheet(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
// Copy text option
|
// Copy text option
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.copy),
|
leading: const Icon(Icons.copy),
|
||||||
@@ -543,6 +564,39 @@ class _MessageBubble extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _showReplySheet(BuildContext context) {
|
||||||
|
// Find the sender contact by public key prefix
|
||||||
|
final contactsProvider = context.read<ContactsProvider>();
|
||||||
|
|
||||||
|
if (message.senderPublicKeyPrefix == null) {
|
||||||
|
ToastLogger.error(context, 'Cannot reply: sender information missing');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find contact by public key prefix (first 6 bytes)
|
||||||
|
final senderKeyHex = message.senderPublicKeyPrefix!
|
||||||
|
.sublist(0, message.senderPublicKeyPrefix!.length < 6 ? message.senderPublicKeyPrefix!.length : 6)
|
||||||
|
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||||
|
.join('');
|
||||||
|
|
||||||
|
final senderContact = contactsProvider.contacts.where((c) {
|
||||||
|
return c.publicKeyHex.startsWith(senderKeyHex);
|
||||||
|
}).firstOrNull;
|
||||||
|
|
||||||
|
if (senderContact == null) {
|
||||||
|
ToastLogger.error(context, 'Cannot reply: contact not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show direct message sheet
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
builder: (context) => DirectMessageSheet(contact: senderContact),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void _showDeleteConfirmation(BuildContext context) {
|
void _showDeleteConfirmation(BuildContext context) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
42
lib/utils/drawing_message_parser.dart
Normal file
42
lib/utils/drawing_message_parser.dart
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import '../models/map_drawing.dart';
|
||||||
|
|
||||||
|
/// Parser for drawing messages transmitted over mesh network
|
||||||
|
class DrawingMessageParser {
|
||||||
|
/// Drawing message prefix
|
||||||
|
static const String prefix = 'D:';
|
||||||
|
|
||||||
|
/// Check if message is a drawing message
|
||||||
|
static bool isDrawingMessage(String text) {
|
||||||
|
return text.startsWith(prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse drawing message text into MapDrawing object
|
||||||
|
/// Returns null if parsing fails
|
||||||
|
static MapDrawing? parseDrawingMessage(String text) {
|
||||||
|
if (!isDrawingMessage(text)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Remove prefix
|
||||||
|
final jsonStr = text.substring(prefix.length);
|
||||||
|
|
||||||
|
// Parse JSON
|
||||||
|
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
|
||||||
|
|
||||||
|
// Use existing fromJson method
|
||||||
|
return MapDrawing.fromJson(json);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create drawing message text from MapDrawing object
|
||||||
|
/// Includes sender name in the message
|
||||||
|
static String createDrawingMessage(MapDrawing drawing, String senderName) {
|
||||||
|
final json = drawing.toNetworkJson(senderName);
|
||||||
|
final jsonStr = jsonEncode(json);
|
||||||
|
return '$prefix$jsonStr';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,14 +34,35 @@ class DrawingLayer extends StatelessWidget {
|
|||||||
/// Create a polyline from a drawing
|
/// Create a polyline from a drawing
|
||||||
Polyline _createPolyline(MapDrawing drawing, {required bool isPreview}) {
|
Polyline _createPolyline(MapDrawing drawing, {required bool isPreview}) {
|
||||||
final points = _getPoints(drawing);
|
final points = _getPoints(drawing);
|
||||||
final opacity = isPreview ? 0.6 : 1.0;
|
|
||||||
|
// Different styles for different drawing sources
|
||||||
|
final double opacity;
|
||||||
|
final double strokeWidth;
|
||||||
|
|
||||||
|
if (isPreview) {
|
||||||
|
// Preview drawing (currently being drawn)
|
||||||
|
opacity = 0.6;
|
||||||
|
strokeWidth = 4.0;
|
||||||
|
} else if (drawing.isReceived) {
|
||||||
|
// Received drawing from another node (thinner, more transparent)
|
||||||
|
opacity = 0.7;
|
||||||
|
strokeWidth = 3.0;
|
||||||
|
} else {
|
||||||
|
// Local drawing (solid line, normal thickness)
|
||||||
|
opacity = 1.0;
|
||||||
|
strokeWidth = 4.0;
|
||||||
|
}
|
||||||
|
|
||||||
return Polyline(
|
return Polyline(
|
||||||
points: points,
|
points: points,
|
||||||
color: drawing.color.withValues(alpha: opacity),
|
color: drawing.color.withValues(alpha: opacity),
|
||||||
strokeWidth: 4.0,
|
strokeWidth: strokeWidth,
|
||||||
borderColor: Colors.white.withValues(alpha: opacity * 0.8),
|
borderColor: Colors.white.withValues(alpha: opacity * 0.8),
|
||||||
borderStrokeWidth: 1.0,
|
borderStrokeWidth: 1.0,
|
||||||
|
// Use dotted pattern for received drawings
|
||||||
|
pattern: drawing.isReceived && !isPreview
|
||||||
|
? StrokePattern.dotted(spacingFactor: 2)
|
||||||
|
: const StrokePattern.solid(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,33 +92,60 @@ class DrawingMarkersLayer extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// Only show delete buttons when showDeleteButtons is true
|
|
||||||
if (!showDeleteButtons) {
|
|
||||||
return const SizedBox.shrink();
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Marker> markers = [];
|
final List<Marker> markers = [];
|
||||||
|
|
||||||
// Add delete markers for each drawing (at the center point)
|
// Add markers for each drawing
|
||||||
for (final drawing in drawings) {
|
for (final drawing in drawings) {
|
||||||
final centerPoint = _getCenterPoint(drawing);
|
final centerPoint = _getCenterPoint(drawing);
|
||||||
if (centerPoint != null) {
|
if (centerPoint != null) {
|
||||||
markers.add(
|
if (showDeleteButtons) {
|
||||||
Marker(
|
// Show delete button when in drawing mode
|
||||||
point: centerPoint,
|
markers.add(
|
||||||
width: 40,
|
Marker(
|
||||||
height: 40,
|
point: centerPoint,
|
||||||
child: GestureDetector(
|
width: 40,
|
||||||
onTap: () {
|
height: 40,
|
||||||
if (onDeleteDrawing != null) {
|
child: GestureDetector(
|
||||||
_showDeleteDialog(context, drawing);
|
onTap: () {
|
||||||
}
|
if (onDeleteDrawing != null) {
|
||||||
},
|
_showDeleteDialog(context, drawing);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: drawing.color.withValues(alpha: 0.9),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(color: Colors.white, width: 2),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.3),
|
||||||
|
blurRadius: 4,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.close,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else if (drawing.isReceived && drawing.senderName != null) {
|
||||||
|
// Show sender badge for received drawings (when not in drawing mode)
|
||||||
|
markers.add(
|
||||||
|
Marker(
|
||||||
|
point: centerPoint,
|
||||||
|
width: 120,
|
||||||
|
height: 30,
|
||||||
child: Container(
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: drawing.color.withValues(alpha: 0.9),
|
color: drawing.color.withValues(alpha: 0.9),
|
||||||
shape: BoxShape.circle,
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(color: Colors.white, width: 2),
|
border: Border.all(color: Colors.white, width: 1.5),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black.withValues(alpha: 0.3),
|
color: Colors.black.withValues(alpha: 0.3),
|
||||||
@@ -106,18 +154,40 @@ class DrawingMarkersLayer extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: const Icon(
|
child: Row(
|
||||||
Icons.close,
|
mainAxisSize: MainAxisSize.min,
|
||||||
color: Colors.white,
|
children: [
|
||||||
size: 20,
|
const Icon(
|
||||||
|
Icons.person,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 14,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Flexible(
|
||||||
|
child: Text(
|
||||||
|
drawing.senderName!,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (markers.isEmpty) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
return MarkerLayer(markers: markers);
|
return MarkerLayer(markers: markers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../../providers/drawing_provider.dart';
|
import '../../providers/drawing_provider.dart';
|
||||||
|
import '../../providers/connection_provider.dart';
|
||||||
|
import '../../providers/contacts_provider.dart';
|
||||||
import '../../models/map_drawing.dart';
|
import '../../models/map_drawing.dart';
|
||||||
|
import '../../models/contact.dart';
|
||||||
|
|
||||||
/// Toolbar for drawing controls on the map
|
/// Toolbar for drawing controls on the map
|
||||||
class DrawingToolbar extends StatelessWidget {
|
class DrawingToolbar extends StatelessWidget {
|
||||||
@@ -50,8 +54,8 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
_getTitleForMode(drawingProvider.drawingMode),
|
_getTitleForMode(drawingProvider.drawingMode),
|
||||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
IconButton(
|
IconButton(
|
||||||
@@ -62,30 +66,33 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 8),
|
||||||
// Color picker
|
// Color picker - more compact
|
||||||
Wrap(
|
Wrap(
|
||||||
spacing: 8,
|
spacing: 4,
|
||||||
|
runSpacing: 4,
|
||||||
children: DrawingColors.palette.map((color) {
|
children: DrawingColors.palette.map((color) {
|
||||||
final isSelected = drawingProvider.selectedColor == color;
|
final isSelected = drawingProvider.selectedColor == color;
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => drawingProvider.setColor(color),
|
onTap: () => drawingProvider.setColor(color),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 32,
|
width: 24,
|
||||||
height: 32,
|
height: 24,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: color,
|
color: color,
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: isSelected ? Colors.white : Colors.grey.shade300,
|
color: isSelected
|
||||||
width: isSelected ? 3 : 2,
|
? Colors.white
|
||||||
|
: Colors.grey.shade300,
|
||||||
|
width: isSelected ? 2 : 1,
|
||||||
),
|
),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
if (isSelected)
|
if (isSelected)
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: color.withValues(alpha: 0.5),
|
color: color.withValues(alpha: 0.5),
|
||||||
blurRadius: 8,
|
blurRadius: 4,
|
||||||
spreadRadius: 2,
|
spreadRadius: 1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -93,14 +100,14 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
? const Icon(
|
? const Icon(
|
||||||
Icons.check,
|
Icons.check,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
size: 16,
|
size: 12,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 8),
|
||||||
// Action buttons
|
// Action buttons
|
||||||
Row(
|
Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@@ -112,6 +119,9 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
icon: const Icon(Icons.undo),
|
icon: const Icon(Icons.undo),
|
||||||
onPressed: () => drawingProvider.cancelCurrentDrawing(),
|
onPressed: () => drawingProvider.cancelCurrentDrawing(),
|
||||||
tooltip: 'Cancel',
|
tooltip: 'Cancel',
|
||||||
|
iconSize: 20,
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
constraints: const BoxConstraints(),
|
||||||
),
|
),
|
||||||
// Complete line drawing
|
// Complete line drawing
|
||||||
if (drawingProvider.drawingMode == DrawingMode.line &&
|
if (drawingProvider.drawingMode == DrawingMode.line &&
|
||||||
@@ -121,31 +131,24 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
onPressed: () => drawingProvider.completeLine(),
|
onPressed: () => drawingProvider.completeLine(),
|
||||||
tooltip: 'Complete Line',
|
tooltip: 'Complete Line',
|
||||||
color: Colors.green,
|
color: Colors.green,
|
||||||
|
iconSize: 20,
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
constraints: const BoxConstraints(),
|
||||||
),
|
),
|
||||||
// Clear all drawings
|
// Clear all drawings
|
||||||
if (drawingProvider.drawings.isNotEmpty)
|
if (drawingProvider.drawings.isNotEmpty)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.delete_sweep),
|
icon: const Icon(Icons.delete_sweep),
|
||||||
onPressed: () => _showClearAllDialog(context, drawingProvider),
|
onPressed: () =>
|
||||||
|
_showClearAllDialog(context, drawingProvider),
|
||||||
tooltip: 'Clear All',
|
tooltip: 'Clear All',
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
|
iconSize: 20,
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
constraints: const BoxConstraints(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
// Instructions
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
_getInstructions(drawingProvider.drawingMode),
|
|
||||||
style: Theme.of(context).textTheme.bodySmall,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -171,8 +174,8 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
Text(
|
Text(
|
||||||
'Drawing Tools',
|
'Drawing Tools',
|
||||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -198,10 +201,28 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
if (drawingProvider.drawings.isNotEmpty) ...[
|
if (drawingProvider.drawings.isNotEmpty) ...[
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.share, color: Colors.blue),
|
||||||
|
title: const Text('Share Drawings'),
|
||||||
|
subtitle: Text(
|
||||||
|
'Broadcast ${drawingProvider.drawings.length} drawings to team',
|
||||||
|
),
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.pop(context);
|
||||||
|
// Small delay to ensure first bottom sheet is fully closed
|
||||||
|
// before opening the second one
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
if (context.mounted) {
|
||||||
|
_showShareDrawingsDialog(context, drawingProvider);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: const Icon(Icons.delete_sweep, color: Colors.red),
|
leading: const Icon(Icons.delete_sweep, color: Colors.red),
|
||||||
title: const Text('Clear All Drawings'),
|
title: const Text('Clear All Drawings'),
|
||||||
subtitle: Text('Remove all ${drawingProvider.drawings.length} drawings'),
|
subtitle: Text(
|
||||||
|
'Remove all ${drawingProvider.drawings.length} drawings',
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
_showClearAllDialog(context, drawingProvider);
|
_showClearAllDialog(context, drawingProvider);
|
||||||
@@ -215,7 +236,10 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Show clear all confirmation dialog
|
/// Show clear all confirmation dialog
|
||||||
void _showClearAllDialog(BuildContext context, DrawingProvider drawingProvider) {
|
void _showClearAllDialog(
|
||||||
|
BuildContext context,
|
||||||
|
DrawingProvider drawingProvider,
|
||||||
|
) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
@@ -233,9 +257,7 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
drawingProvider.clearAllDrawings();
|
drawingProvider.clearAllDrawings();
|
||||||
},
|
},
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||||
foregroundColor: Colors.red,
|
|
||||||
),
|
|
||||||
child: const Text('Clear All'),
|
child: const Text('Clear All'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -278,4 +300,262 @@ class DrawingToolbar extends StatelessWidget {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Show share drawings dialog
|
||||||
|
void _showShareDrawingsDialog(
|
||||||
|
BuildContext context,
|
||||||
|
DrawingProvider drawingProvider,
|
||||||
|
) {
|
||||||
|
debugPrint('🎨 [DrawingToolbar] _showShareDrawingsDialog called');
|
||||||
|
|
||||||
|
// Capture the root context BEFORE showing the modal
|
||||||
|
final rootContext = context;
|
||||||
|
|
||||||
|
// Read providers BEFORE any async operations or dialogs
|
||||||
|
// This ensures we have the correct BuildContext
|
||||||
|
final connectionProvider = Provider.of<ConnectionProvider>(context, listen: false);
|
||||||
|
final contactsProvider = Provider.of<ContactsProvider>(context, listen: false);
|
||||||
|
|
||||||
|
debugPrint(' Connection status: ${connectionProvider.deviceInfo.isConnected}');
|
||||||
|
|
||||||
|
if (!connectionProvider.deviceInfo.isConnected) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('Not connected to device'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get device name for sender identification
|
||||||
|
final senderName = connectionProvider.deviceInfo.selfName ?? 'Unknown';
|
||||||
|
|
||||||
|
// Filter drawings (only share local drawings, not received ones)
|
||||||
|
final localDrawings = drawingProvider.drawings
|
||||||
|
.where((d) => !d.isReceived)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
debugPrint(' Local drawings count: ${localDrawings.length}');
|
||||||
|
debugPrint(' Total drawings count: ${drawingProvider.drawings.length}');
|
||||||
|
|
||||||
|
if (localDrawings.isEmpty) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('No local drawings to share'),
|
||||||
|
backgroundColor: Colors.orange,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get available rooms
|
||||||
|
final rooms = contactsProvider.rooms;
|
||||||
|
debugPrint(' Available rooms: ${rooms.length}');
|
||||||
|
|
||||||
|
debugPrint(' Showing modal bottom sheet...');
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
|
builder: (sheetContext) => Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.share),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
'Share ${localDrawings.length} Drawing${localDrawings.length > 1 ? 's' : ''}',
|
||||||
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
// Option: Send to Public Channel
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.public, color: Colors.blue),
|
||||||
|
title: const Text('Public Channel'),
|
||||||
|
subtitle: const Text('Broadcast to all nearby nodes (ephemeral)'),
|
||||||
|
onTap: () async {
|
||||||
|
debugPrint('📤 [DrawingToolbar] Public Channel tapped');
|
||||||
|
// Share BEFORE popping the navigator
|
||||||
|
await _shareDrawingsToChannel(
|
||||||
|
sheetContext,
|
||||||
|
localDrawings,
|
||||||
|
connectionProvider,
|
||||||
|
senderName,
|
||||||
|
);
|
||||||
|
if (sheetContext.mounted) {
|
||||||
|
Navigator.pop(sheetContext);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
// Option: Send to Room
|
||||||
|
if (rooms.isNotEmpty) ...[
|
||||||
|
...rooms.map(
|
||||||
|
(room) => ListTile(
|
||||||
|
leading: const Icon(Icons.meeting_room, color: Colors.green),
|
||||||
|
title: Text(room.advName),
|
||||||
|
subtitle: const Text('Stored permanently in room'),
|
||||||
|
onTap: () async {
|
||||||
|
debugPrint('📤 [DrawingToolbar] Room ${room.advName} tapped');
|
||||||
|
// Share BEFORE popping the navigator
|
||||||
|
await _shareDrawingsToRoom(
|
||||||
|
sheetContext,
|
||||||
|
localDrawings,
|
||||||
|
connectionProvider,
|
||||||
|
senderName,
|
||||||
|
room,
|
||||||
|
);
|
||||||
|
if (sheetContext.mounted) {
|
||||||
|
Navigator.pop(sheetContext);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Share drawings to public channel
|
||||||
|
Future<void> _shareDrawingsToChannel(
|
||||||
|
BuildContext context,
|
||||||
|
List<MapDrawing> drawings,
|
||||||
|
ConnectionProvider connectionProvider,
|
||||||
|
String senderName,
|
||||||
|
) async {
|
||||||
|
debugPrint('📤 [DrawingToolbar] _shareDrawingsToChannel called');
|
||||||
|
debugPrint(' Drawings to share: ${drawings.length}');
|
||||||
|
debugPrint(' Sender name: $senderName');
|
||||||
|
debugPrint(' Context mounted: ${context.mounted}');
|
||||||
|
|
||||||
|
if (!context.mounted) {
|
||||||
|
debugPrint('❌ Context not mounted, aborting');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final drawingProvider = Provider.of<DrawingProvider>(context, listen: false);
|
||||||
|
int successCount = 0;
|
||||||
|
|
||||||
|
for (final drawing in drawings) {
|
||||||
|
try {
|
||||||
|
debugPrint(' Creating message for drawing ${drawing.id}...');
|
||||||
|
final message = drawingProvider.createDrawingBroadcastMessage(
|
||||||
|
drawing,
|
||||||
|
senderName,
|
||||||
|
);
|
||||||
|
debugPrint(' Message created (${message.length} chars): ${message.substring(0, message.length > 100 ? 100 : message.length)}...');
|
||||||
|
debugPrint(' Sending to channel 0...');
|
||||||
|
await connectionProvider.sendChannelMessage(
|
||||||
|
channelIdx: 0,
|
||||||
|
text: message,
|
||||||
|
);
|
||||||
|
debugPrint(' ✅ Sent successfully');
|
||||||
|
successCount++;
|
||||||
|
// Small delay between messages to avoid overwhelming the device
|
||||||
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
debugPrint('❌ Failed to share drawing ${drawing.id}: $e');
|
||||||
|
debugPrint(' Stack trace: $stackTrace');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debugPrint(' Share complete: $successCount/${drawings.length} sent');
|
||||||
|
debugPrint(' Context mounted after send: ${context.mounted}');
|
||||||
|
|
||||||
|
if (!context.mounted) {
|
||||||
|
debugPrint('❌ Context not mounted, cannot show snackbar');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Shared $successCount/${drawings.length} drawings to Public Channel',
|
||||||
|
),
|
||||||
|
backgroundColor: successCount == drawings.length
|
||||||
|
? Colors.green
|
||||||
|
: Colors.orange,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Share drawings to a specific room
|
||||||
|
Future<void> _shareDrawingsToRoom(
|
||||||
|
BuildContext context,
|
||||||
|
List<MapDrawing> drawings,
|
||||||
|
ConnectionProvider connectionProvider,
|
||||||
|
String senderName,
|
||||||
|
Contact room,
|
||||||
|
) async {
|
||||||
|
debugPrint('📤 [DrawingToolbar] _shareDrawingsToRoom called');
|
||||||
|
debugPrint(' Room: ${room.advName}');
|
||||||
|
debugPrint(' Drawings to share: ${drawings.length}');
|
||||||
|
debugPrint(' Sender name: $senderName');
|
||||||
|
debugPrint(' Context mounted: ${context.mounted}');
|
||||||
|
|
||||||
|
if (!context.mounted) {
|
||||||
|
debugPrint('❌ Context not mounted, aborting');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final drawingProvider = Provider.of<DrawingProvider>(context, listen: false);
|
||||||
|
int successCount = 0;
|
||||||
|
|
||||||
|
for (final drawing in drawings) {
|
||||||
|
try {
|
||||||
|
debugPrint(' Creating message for drawing ${drawing.id}...');
|
||||||
|
final message = drawingProvider.createDrawingBroadcastMessage(
|
||||||
|
drawing,
|
||||||
|
senderName,
|
||||||
|
);
|
||||||
|
debugPrint(' Message created (${message.length} chars): ${message.substring(0, message.length > 100 ? 100 : message.length)}...');
|
||||||
|
debugPrint(' Sending to room ${room.advName}...');
|
||||||
|
await connectionProvider.sendTextMessage(
|
||||||
|
contactPublicKey: room.publicKey,
|
||||||
|
text: message,
|
||||||
|
);
|
||||||
|
debugPrint(' ✅ Sent successfully');
|
||||||
|
successCount++;
|
||||||
|
// Small delay between messages to avoid overwhelming the device
|
||||||
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
} catch (e, stackTrace) {
|
||||||
|
debugPrint(
|
||||||
|
'❌ Failed to share drawing ${drawing.id} to ${room.advName}: $e',
|
||||||
|
);
|
||||||
|
debugPrint(' Stack trace: $stackTrace');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debugPrint(' Share complete: $successCount/${drawings.length} sent');
|
||||||
|
debugPrint(' Context mounted after send: ${context.mounted}');
|
||||||
|
|
||||||
|
if (!context.mounted) {
|
||||||
|
debugPrint('❌ Context not mounted, cannot show snackbar');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Shared $successCount/${drawings.length} drawings to ${room.advName}',
|
||||||
|
),
|
||||||
|
backgroundColor: successCount == drawings.length
|
||||||
|
? Colors.green
|
||||||
|
: Colors.orange,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user