1.0.2
This commit is contained in:
+11
-1
@@ -36,7 +36,17 @@ class MyApp extends StatelessWidget {
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const HomeScreen(), // Change LoginScreen to HomeScreen
|
||||
darkTheme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.blue,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
useMaterial3: true,
|
||||
dialogTheme: DialogThemeData(
|
||||
backgroundColor: Colors.grey[900],
|
||||
),
|
||||
),
|
||||
home: const HomeScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class _CalendarScreenState extends State<CalendarScreen> {
|
||||
String _bulletColor = 'Blue';
|
||||
String _selectedLanguage = 'English';
|
||||
bool _showContacts = false;
|
||||
bool _showDebugPreview = true;
|
||||
bool _showDebugPreview = false;
|
||||
|
||||
// Members contact list
|
||||
final List<Contact> _contacts = [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:upgrader/upgrader.dart';
|
||||
import '../utils/translations.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
@@ -170,6 +171,224 @@ Future<void> _saveLanguage(String language) async {
|
||||
_loadCameraIPs();
|
||||
}
|
||||
|
||||
Future<void> _checkForUpdatesManual() async {
|
||||
// Check for updates without the 24-hour throttling
|
||||
final upgrader = Upgrader();
|
||||
try {
|
||||
final isUpdateAvailable = await upgrader.isUpdateAvailable();
|
||||
if (isUpdateAvailable && mounted) {
|
||||
_showCustomUpdateDialog(true);
|
||||
} else if (mounted) {
|
||||
// Show "No updates available" dialog
|
||||
_showNoUpdatesDialog();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_t('Update check failed'))),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _showCustomUpdateDialog(bool updateAvailable) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Colors.grey[900],
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.update,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
_t('Update Available'),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_t('A new version of the app is available'),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey[300],
|
||||
height: 1.5,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[800],
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_t('Later'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
// Trigger the update using the upgrader package
|
||||
_triggerUpdate();
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_t('Update'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showNoUpdatesDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Colors.grey[900],
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.check_circle,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
_t('No updates available'),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_t('You are using the latest version'),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey[300],
|
||||
height: 1.5,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.of(context).pop(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_t('OK'),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _triggerUpdate() {
|
||||
// Use Upgrader to trigger the app store/play store
|
||||
try {
|
||||
Upgrader().sendUserToAppStore();
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_t('Failed to open app store'))),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _editCameraIP(int index) {
|
||||
TextEditingController controller = TextEditingController(
|
||||
text: _cameraIPs[index],
|
||||
@@ -314,6 +533,8 @@ Future<void> _saveLanguage(String language) async {
|
||||
const SizedBox(height: 8),
|
||||
_buildLanguageSelector(),
|
||||
const SizedBox(height: 16),
|
||||
_buildCheckUpdateButton(),
|
||||
const SizedBox(height: 16),
|
||||
_buildBulletColorSelector(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
@@ -372,6 +593,46 @@ Future<void> _saveLanguage(String language) async {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCheckUpdateButton() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
_t("Updates"),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: _checkForUpdatesManual,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[300],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.system_update, color: Colors.black54),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_t('Check for Updates'),
|
||||
style: const TextStyle(color: Colors.black87, fontSize: 14),
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: Colors.black54),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBulletColorSelector() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:upgrader/upgrader.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../utils/translations.dart';
|
||||
import '../widgets/custom_upgrade_alert.dart';
|
||||
|
||||
// GitHub Configuration
|
||||
const String _githubRepoOwner = 'Bl3kiiie';
|
||||
const String _githubRepoName = 'shooting_app';
|
||||
const String _githubToken =
|
||||
'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'; // Replace with your GitHub Personal Access Token
|
||||
|
||||
class UpdateChecker {
|
||||
static final UpdateChecker _instance = UpdateChecker._internal();
|
||||
|
||||
factory UpdateChecker() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
UpdateChecker._internal();
|
||||
|
||||
Future<void> checkForUpdate(BuildContext context, String language) async {
|
||||
// Check if we've already checked today
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final lastCheckTime = prefs.getInt('last_update_check_time') ?? 0;
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
final oneDayInMilliseconds = 24 * 60 * 60 * 1000;
|
||||
|
||||
// Only check once per day
|
||||
if (now - lastCheckTime < oneDayInMilliseconds) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the last check time
|
||||
await prefs.setInt('last_update_check_time', now);
|
||||
|
||||
final upgrader = Upgrader();
|
||||
|
||||
try {
|
||||
// Check if update is available
|
||||
final isUpdateAvailable = await upgrader.isUpdateAvailable();
|
||||
|
||||
if (isUpdateAvailable && context.mounted) {
|
||||
_showCustomUpdateDialog(context, language);
|
||||
}
|
||||
} catch (e) {
|
||||
// Silently fail if update check fails
|
||||
print('Update check failed: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void _showCustomUpdateDialog(BuildContext context, String language) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return CustomUpdateDialog(
|
||||
title: AppTranslations.translate('Update Available', language),
|
||||
message: AppTranslations.translate(
|
||||
'A new version of the app is available', language),
|
||||
updateButtonText: AppTranslations.translate('Update', language),
|
||||
laterButtonText: AppTranslations.translate('Later', language),
|
||||
onUpdate: () {
|
||||
Upgrader().sendUserToAppStore();
|
||||
},
|
||||
onLater: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -584,6 +584,46 @@ class AppTranslations {
|
||||
'English': 'copied to clipboard',
|
||||
'Slovenian': 'kopirano v odložišče',
|
||||
},
|
||||
|
||||
// App Update translations
|
||||
'Update Available': {
|
||||
'English': 'Update Available',
|
||||
'Slovenian': 'Posodobitev je na voljo',
|
||||
},
|
||||
'A new version of the app is available': {
|
||||
'English': 'A new version of the app is available',
|
||||
'Slovenian': 'Nova različica aplikacije je na voljo',
|
||||
},
|
||||
'Update': {
|
||||
'English': 'Update',
|
||||
'Slovenian': 'Posodobi',
|
||||
},
|
||||
'Later': {
|
||||
'English': 'Later',
|
||||
'Slovenian': 'Kasneje',
|
||||
},
|
||||
|
||||
// App Update Check Button
|
||||
'Check for Updates': {
|
||||
'English': 'Check for Updates',
|
||||
'Slovenian': 'Preveri za posodobitve',
|
||||
},
|
||||
'No updates available': {
|
||||
'English': 'No updates available',
|
||||
'Slovenian': 'Ni dostopnih posodobitev',
|
||||
},
|
||||
'You are using the latest version': {
|
||||
'English': 'You are using the latest version',
|
||||
'Slovenian': 'Uporabljate najnovejšo različico',
|
||||
},
|
||||
'Updates': {
|
||||
'English': 'Updates',
|
||||
'Slovenian': 'Posodobitve',
|
||||
},
|
||||
'OK': {
|
||||
'English': 'OK',
|
||||
'Slovenian': 'V redu',
|
||||
},
|
||||
};
|
||||
|
||||
static String translate(String key, String language) {
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:upgrader/upgrader.dart';
|
||||
import '../utils/translations.dart';
|
||||
|
||||
class CustomUpgradeAlert extends StatefulWidget {
|
||||
final Widget child;
|
||||
final String language;
|
||||
|
||||
const CustomUpgradeAlert({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.language,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CustomUpgradeAlert> createState() => _CustomUpgradeAlertState();
|
||||
}
|
||||
|
||||
class _CustomUpgradeAlertState extends State<CustomUpgradeAlert> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return UpgradeAlert(
|
||||
child: widget.child,
|
||||
upgrader: Upgrader(
|
||||
debugDisplayAlways: true,
|
||||
),
|
||||
dialogStyle: UpgradeDialogStyle.material,
|
||||
shouldPopScope: () => true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CustomUpdateDialog extends StatelessWidget {
|
||||
final String title;
|
||||
final String message;
|
||||
final String updateButtonText;
|
||||
final String laterButtonText;
|
||||
final VoidCallback onUpdate;
|
||||
final VoidCallback onLater;
|
||||
|
||||
const CustomUpdateDialog({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.message,
|
||||
required this.updateButtonText,
|
||||
required this.laterButtonText,
|
||||
required this.onUpdate,
|
||||
required this.onLater,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
backgroundColor: Colors.grey[900],
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// App Icon
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.update,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Title
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Message
|
||||
Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.grey[300],
|
||||
height: 1.5,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
// Buttons
|
||||
Row(
|
||||
children: [
|
||||
// Later Button
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: onLater,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[800],
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
laterButtonText,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Update Button
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: onUpdate,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
updateButtonText,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user