Apply dart format to all files
This commit is contained in:
+1
-3
@@ -35,9 +35,7 @@ class MyApp extends StatelessWidget {
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
),
|
||||
supportedLocales: const [
|
||||
Locale('en', ''),
|
||||
],
|
||||
supportedLocales: const [Locale('en', '')],
|
||||
initialRoute: '/',
|
||||
routes: {
|
||||
'/': (_) => const LoginScreen(),
|
||||
|
||||
@@ -3,20 +3,20 @@ import 'package:flutter/material.dart';
|
||||
class MapProvider with ChangeNotifier {
|
||||
bool _isInitialized = false;
|
||||
String _error = '';
|
||||
|
||||
|
||||
bool get isInitialized => _isInitialized;
|
||||
String get error => _error;
|
||||
|
||||
|
||||
void initialize() {
|
||||
_isInitialized = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
void handleError(String error) {
|
||||
_error = error;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
void clearError() {
|
||||
_error = '';
|
||||
notifyListeners();
|
||||
|
||||
+124
-113
@@ -67,141 +67,152 @@ class _LoginScreenState extends State<LoginScreen>
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'Family Safety',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
if (!kIsWeb) ...[
|
||||
TextField(
|
||||
controller: _serverUrlController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Server URL',
|
||||
hintText: 'https://example.com/api',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.cloud_outlined),
|
||||
const Text(
|
||||
'Family Safety',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
keyboardType: TextInputType.url,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
tabs: const [
|
||||
Tab(text: 'Login'),
|
||||
Tab(text: 'Register'),
|
||||
const SizedBox(height: 24),
|
||||
if (!kIsWeb) ...[
|
||||
TextField(
|
||||
controller: _serverUrlController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Server URL',
|
||||
hintText: 'https://example.com/api',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.cloud_outlined),
|
||||
),
|
||||
keyboardType: TextInputType.url,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
TextField(
|
||||
controller: _loginController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Login',
|
||||
border: OutlineInputBorder(),
|
||||
TabBar(
|
||||
controller: _tabController,
|
||||
tabs: const [
|
||||
Tab(text: 'Login'),
|
||||
Tab(text: 'Register'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _passwordController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(),
|
||||
const SizedBox(height: 24),
|
||||
TextField(
|
||||
controller: _loginController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Login',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
if (_tabController.index == 1) ...[
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _secretKeyController,
|
||||
controller: _passwordController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Secret Key',
|
||||
labelText: 'Password',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
if (authProvider.error.isNotEmpty)
|
||||
Text(
|
||||
authProvider.error,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: authProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
if (!kIsWeb) {
|
||||
final status = await Geolocator.checkPermission();
|
||||
if (status == LocationPermission.denied) {
|
||||
final requested = await Geolocator.requestPermission();
|
||||
if (requested == LocationPermission.denied) {
|
||||
authProvider.setError('Location permission denied');
|
||||
if (_tabController.index == 1) ...[
|
||||
const SizedBox(height: 16),
|
||||
TextField(
|
||||
controller: _secretKeyController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Secret Key',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
if (authProvider.error.isNotEmpty)
|
||||
Text(
|
||||
authProvider.error,
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: authProvider.isLoading
|
||||
? null
|
||||
: () async {
|
||||
if (!kIsWeb) {
|
||||
final status =
|
||||
await Geolocator.checkPermission();
|
||||
if (status == LocationPermission.denied) {
|
||||
final requested =
|
||||
await Geolocator.requestPermission();
|
||||
if (requested == LocationPermission.denied) {
|
||||
authProvider.setError(
|
||||
'Location permission denied',
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (status ==
|
||||
LocationPermission.deniedForever) {
|
||||
authProvider.setError(
|
||||
'Location permission permanently denied. Please enable it in settings.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (status == LocationPermission.deniedForever) {
|
||||
authProvider.setError('Location permission permanently denied. Please enable it in settings.');
|
||||
return;
|
||||
if (!kIsWeb) {
|
||||
final newUrl = _serverUrlController.text.trim();
|
||||
if (newUrl.isNotEmpty &&
|
||||
newUrl != settings.baseUrl) {
|
||||
ApiConfig.setBaseUrl(newUrl);
|
||||
await settings.setBaseUrl(newUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!kIsWeb) {
|
||||
final newUrl = _serverUrlController.text.trim();
|
||||
if (newUrl.isNotEmpty && newUrl != settings.baseUrl) {
|
||||
ApiConfig.setBaseUrl(newUrl);
|
||||
await settings.setBaseUrl(newUrl);
|
||||
}
|
||||
}
|
||||
if (_tabController.index == 0) {
|
||||
try {
|
||||
await authProvider.login(
|
||||
_loginController.text,
|
||||
_passwordController.text,
|
||||
if (_tabController.index == 0) {
|
||||
try {
|
||||
await authProvider.login(
|
||||
_loginController.text,
|
||||
_passwordController.text,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(
|
||||
context,
|
||||
).pushReplacementNamed('/map');
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
} else {
|
||||
if (_secretKeyController.text != _secretKey) {
|
||||
authProvider.setError('Invalid secret key');
|
||||
return;
|
||||
}
|
||||
Digest digest = md5.convert(
|
||||
utf8.encode(_secretKeyController.text),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(
|
||||
context,
|
||||
).pushReplacementNamed('/map');
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
String secretKeyHash = hex.encode(digest.bytes);
|
||||
try {
|
||||
await authProvider.register(
|
||||
_loginController.text,
|
||||
_passwordController.text,
|
||||
secretKeyHash,
|
||||
);
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (_secretKeyController.text != _secretKey) {
|
||||
authProvider.setError('Invalid secret key');
|
||||
return;
|
||||
}
|
||||
Digest digest = md5.convert(
|
||||
utf8.encode(_secretKeyController.text),
|
||||
);
|
||||
String secretKeyHash = hex.encode(digest.bytes);
|
||||
try {
|
||||
await authProvider.register(
|
||||
_loginController.text,
|
||||
_passwordController.text,
|
||||
secretKeyHash,
|
||||
);
|
||||
} catch (e) {
|
||||
// Error is handled by provider
|
||||
}
|
||||
}
|
||||
},
|
||||
child: authProvider.isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(
|
||||
_tabController.index == 0 ? 'Login' : 'Register',
|
||||
),
|
||||
),
|
||||
],
|
||||
},
|
||||
child: authProvider.isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Text(
|
||||
_tabController.index == 0 ? 'Login' : 'Register',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,15 @@ import '../config/api.dart';
|
||||
|
||||
class GeoService {
|
||||
final http.Client _client;
|
||||
|
||||
|
||||
GeoService({http.Client? client}) : _client = client ?? http.Client();
|
||||
|
||||
Future<void> updatePosition(String token, String id, double x, double y) async {
|
||||
Future<void> updatePosition(
|
||||
String token,
|
||||
String id,
|
||||
double x,
|
||||
double y,
|
||||
) async {
|
||||
final response = await _client.put(
|
||||
Uri.parse('${ApiConfig.geoUrl}?id=$id'),
|
||||
headers: {
|
||||
@@ -16,9 +21,9 @@ class GeoService {
|
||||
},
|
||||
body: jsonEncode({'x': x, 'y': y}),
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Failed to update position');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,17 @@ import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
class PlatformService {
|
||||
bool get isWeb => kIsWeb;
|
||||
bool get isNative => !kIsWeb;
|
||||
String get platformName => isWeb ? 'web' : Platform.isAndroid ? 'android' : Platform.isIOS ? 'ios' : Platform.isWindows ? 'windows' : Platform.isMacOS ? 'macos' : Platform.isLinux ? 'linux' : 'unknown';
|
||||
String get platformName => isWeb
|
||||
? 'web'
|
||||
: Platform.isAndroid
|
||||
? 'android'
|
||||
: Platform.isIOS
|
||||
? 'ios'
|
||||
: Platform.isWindows
|
||||
? 'windows'
|
||||
: Platform.isMacOS
|
||||
? 'macos'
|
||||
: Platform.isLinux
|
||||
? 'linux'
|
||||
: 'unknown';
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SettingsService {
|
||||
static const String _baseUrlKey = 'server_base_url';
|
||||
static const String _defaultBaseUrl = 'https://family-safety.onrender.com/api';
|
||||
static const String _defaultBaseUrl =
|
||||
'https://family-safety.onrender.com/api';
|
||||
|
||||
String _baseUrl = _defaultBaseUrl;
|
||||
bool _initialized = false;
|
||||
|
||||
@@ -4,10 +4,14 @@ import '../config/api.dart';
|
||||
|
||||
class ShareService {
|
||||
final http.Client _client;
|
||||
|
||||
|
||||
ShareService({http.Client? client}) : _client = client ?? http.Client();
|
||||
|
||||
Future<Map<String, dynamic>> createShare(String token, double x, double y) async {
|
||||
Future<Map<String, dynamic>> createShare(
|
||||
String token,
|
||||
double x,
|
||||
double y,
|
||||
) async {
|
||||
final response = await _client.post(
|
||||
Uri.parse(ApiConfig.shareUrl),
|
||||
headers: {
|
||||
@@ -16,7 +20,7 @@ class ShareService {
|
||||
},
|
||||
body: jsonEncode({'x': x, 'y': y}),
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode == 201) {
|
||||
try {
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
@@ -25,22 +29,29 @@ class ShareService {
|
||||
'share_id': data['share_id']?.toString() ?? '',
|
||||
};
|
||||
} catch (e) {
|
||||
throw Exception('Failed to parse response: $e | Body: ${response.body.substring(0, response.body.length > 200 ? 200 : response.body.length)}');
|
||||
throw Exception(
|
||||
'Failed to parse response: $e | Body: ${response.body.substring(0, response.body.length > 200 ? 200 : response.body.length)}',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
final errorBody = response.body.length > 200 ? response.body.substring(0, 200) : response.body;
|
||||
throw Exception('Failed to create share link: ${response.statusCode} - $errorBody');
|
||||
final errorBody = response.body.length > 200
|
||||
? response.body.substring(0, 200)
|
||||
: response.body;
|
||||
throw Exception(
|
||||
'Failed to create share link: ${response.statusCode} - $errorBody',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getPositionByShareId(String token, String shareId) async {
|
||||
Future<Map<String, dynamic>> getPositionByShareId(
|
||||
String token,
|
||||
String shareId,
|
||||
) async {
|
||||
final response = await _client.get(
|
||||
Uri.parse('${ApiConfig.watchUrl}?share_id=$shareId'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
headers: {'Authorization': 'Bearer $token'},
|
||||
);
|
||||
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
return {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class AppConstants {
|
||||
static const String appName = 'Family Safety';
|
||||
|
||||
|
||||
// Default coordinates (Moscow)
|
||||
static const double defaultLatitude = 55.7558;
|
||||
static const double defaultLongitude = 37.6173;
|
||||
|
||||
|
||||
// Share link expiration (5 minutes in seconds)
|
||||
static const int shareExpirationSeconds = 300;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
|
||||
class StringUtil {
|
||||
static bool isValidEmail(String email) {
|
||||
final regExp = RegExp(r'^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)*\.(\w+)$');
|
||||
return regExp.hasMatch(email);
|
||||
}
|
||||
|
||||
|
||||
static String truncate(String text, int maxLength) {
|
||||
if (text.length <= maxLength) return text;
|
||||
return '${text.substring(0, maxLength)}...';
|
||||
}
|
||||
|
||||
|
||||
static String formatDateTime(String dateTime) {
|
||||
try {
|
||||
final date = DateTime.parse(dateTime);
|
||||
return '${date.day}/${date.month}/${date.year} '
|
||||
'${date.hour}:${date.minute.toString().padLeft(2, '0')}';
|
||||
'${date.hour}:${date.minute.toString().padLeft(2, '0')}';
|
||||
} catch (e) {
|
||||
return dateTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,8 @@ import 'package:flutter/material.dart';
|
||||
class ErrorDisplay extends StatelessWidget {
|
||||
final String message;
|
||||
final VoidCallback? onRetry;
|
||||
|
||||
const ErrorDisplay({
|
||||
super.key,
|
||||
required this.message,
|
||||
this.onRetry,
|
||||
});
|
||||
|
||||
const ErrorDisplay({super.key, required this.message, this.onRetry});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -18,11 +14,7 @@ class ErrorDisplay extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.error_outline,
|
||||
size: 48,
|
||||
color: Colors.red,
|
||||
),
|
||||
const Icon(Icons.error_outline, size: 48, color: Colors.red),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
message,
|
||||
@@ -31,14 +23,11 @@ class ErrorDisplay extends StatelessWidget {
|
||||
),
|
||||
if (onRetry != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: onRetry,
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
ElevatedButton(onPressed: onRetry, child: const Text('Retry')),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,8 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class LoadingIndicator extends StatelessWidget {
|
||||
final String message;
|
||||
|
||||
const LoadingIndicator({
|
||||
super.key,
|
||||
this.message = 'Loading...',
|
||||
});
|
||||
|
||||
const LoadingIndicator({super.key, this.message = 'Loading...'});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -16,12 +13,9 @@ class LoadingIndicator extends StatelessWidget {
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
message,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
Text(message, style: const TextStyle(fontSize: 16)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user