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