Skip to content

Commit

Permalink
improved dark mode and removed github status
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Aug 23, 2024
1 parent 051d343 commit 4267ba0
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 85 deletions.
5 changes: 2 additions & 3 deletions lib/lock_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class LockProvider with ChangeNotifier {
} else {
return {
'success': false,
'message':
'Biometric authentication is not available on this device'
'message': 'Biometric authentication is not available on this device'
};
}
} on PlatformException catch (e) {
Expand Down Expand Up @@ -127,4 +126,4 @@ class LockProvider with ChangeNotifier {
await prefs.setInt('lockDurationMinutes', minutes);
notifyListeners();
}
}
}
35 changes: 15 additions & 20 deletions lib/lock_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import 'package:provider/provider.dart';
import 'package:heroicons/heroicons.dart';
import 'lock_provider.dart';
import 'user_provider.dart';
import 'auth_manager.dart';

class LockScreen extends StatefulWidget {
final Widget child;
final AuthManager authManager;

const LockScreen({Key? key, required this.child}) : super(key: key);
const LockScreen({Key? key, required this.child, required this.authManager}) : super(key: key);

@override
_LockScreenState createState() => _LockScreenState();
}

class _LockScreenState extends State<LockScreen>
with WidgetsBindingObserver, TickerProviderStateMixin {
class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver, TickerProviderStateMixin {
bool _isChecking = true;
late AnimationController _lockIconController;
late Animation<double> _lockIconAnimation;
Expand All @@ -28,11 +29,10 @@ class _LockScreenState extends State<LockScreen>
});

_lockIconController = AnimationController(
duration: const Duration(milliseconds: 300), // Increased animation speed
duration: const Duration(milliseconds: 300),
vsync: this,
);
_lockIconAnimation =
Tween<double>(begin: 0, end: 1).animate(_lockIconController);
_lockIconAnimation = Tween<double>(begin: 0, end: 1).animate(_lockIconController);
}

@override
Expand Down Expand Up @@ -68,7 +68,7 @@ class _LockScreenState extends State<LockScreen>
if (_isChecking) {
return _buildLoadingScreen();
}
if (lockProvider.isLockEnabled && lockProvider.isAppLocked) {
if (widget.authManager.isLoggedIn && lockProvider.isLockEnabled && lockProvider.isAppLocked) {
return _buildLockScreen(context, lockProvider);
}
return widget.child;
Expand Down Expand Up @@ -111,7 +111,7 @@ class _LockScreenState extends State<LockScreen>
),
),
_buildUnlockButton(context, lockProvider),
SizedBox(height: 60), // Increased bottom padding
SizedBox(height: 60),
],
),
),
Expand All @@ -129,9 +129,7 @@ class _LockScreenState extends State<LockScreen>
return Transform.rotate(
angle: _lockIconAnimation.value * 2 * 3.14159,
child: HeroIcon(
_lockIconAnimation.value < 0.5
? HeroIcons.lockClosed
: HeroIcons.lockOpen,
_lockIconAnimation.value < 0.5 ? HeroIcons.lockClosed : HeroIcons.lockOpen,
size: 48,
color: theme.colorScheme.primary,
),
Expand All @@ -158,11 +156,9 @@ class _LockScreenState extends State<LockScreen>
backgroundColor: theme.colorScheme.primary.withOpacity(0.1),
child: user?.personalInfo.avatarUrl == null
? Text(
user?.personalInfo.firstName.substring(0, 1).toUpperCase() ??
'U',
style:
TextStyle(fontSize: 48, color: theme.colorScheme.primary),
)
user?.personalInfo.firstName.substring(0, 1).toUpperCase() ?? 'U',
style: TextStyle(fontSize: 48, color: theme.colorScheme.primary),
)
: null,
),
);
Expand Down Expand Up @@ -271,8 +267,7 @@ class _LockScreenState extends State<LockScreen>
);
}

Future<void> _verifyPin(BuildContext context, LockProvider lockProvider,
String enteredPin) async {
Future<void> _verifyPin(BuildContext context, LockProvider lockProvider, String enteredPin) async {
if (await lockProvider.checkPin(enteredPin)) {
await _animateUnlock();
lockProvider.unlockApp();
Expand All @@ -286,7 +281,7 @@ class _LockScreenState extends State<LockScreen>

Future<void> _animateUnlock() async {
await _lockIconController.forward();
await Future.delayed(const Duration(milliseconds: 300)); // Reduced delay
await Future.delayed(const Duration(milliseconds: 300));
_lockIconController.reset();
}
}
}
100 changes: 74 additions & 26 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:vanguard/remote_servers_page.dart';
import 'package:vanguard/tag_page.dart';
import 'package:vanguard/tag_provider.dart';
Expand All @@ -19,23 +21,60 @@ import 'login_page.dart';
import 'backup_tasks_page.dart';
import 'logs_page.dart';
import 'profile_page.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'dart:io';
import 'maintenance_banner.dart';
import 'bottom_nav_bar.dart';

enum ThemeMode { light, dark, auto }

class ThemeProvider with ChangeNotifier {
bool _isDarkMode = true;
static const String _themePreferenceKey = 'theme_preference';
static const String _themeAutoKey = 'theme_auto';

late bool _isDarkMode;
late ThemeMode _themeMode;
late SharedPreferences _prefs;

ThemeProvider() {
_loadPreferences();
}

bool get isDarkMode => _isDarkMode;
ThemeMode get themeMode => _themeMode;

void toggleTheme() {
_isDarkMode = !_isDarkMode;
Future<void> _loadPreferences() async {
_prefs = await SharedPreferences.getInstance();
_themeMode = ThemeMode.values[_prefs.getInt(_themeAutoKey) ?? ThemeMode.auto.index];
_updateThemeMode();
}

void _updateThemeMode() {
if (_themeMode == ThemeMode.auto) {
var brightness = SchedulerBinding.instance.window.platformBrightness;
_isDarkMode = brightness == Brightness.dark;
} else {
_isDarkMode = _themeMode == ThemeMode.dark;
}
_prefs.setBool(_themePreferenceKey, _isDarkMode);
notifyListeners();
}

void setThemeMode(ThemeMode mode) {
_themeMode = mode;
_prefs.setInt(_themeAutoKey, mode.index);
_updateThemeMode();
}

void toggleTheme() {
if (_themeMode == ThemeMode.auto) {
setThemeMode(_isDarkMode ? ThemeMode.light : ThemeMode.dark);
} else {
setThemeMode(_themeMode == ThemeMode.light ? ThemeMode.dark : ThemeMode.light);
}
}

ThemeData get currentTheme => _isDarkMode ? darkTheme : lightTheme;

static final darkTheme = ThemeData(
Expand All @@ -45,12 +84,9 @@ class ThemeProvider with ChangeNotifier {
cardColor: Colors.grey[900],
fontFamily: 'Poppins',
textTheme: const TextTheme(
displayLarge: TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold, color: Colors.white),
titleLarge: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.w500, color: Colors.white),
bodyMedium: TextStyle(
fontSize: 14.0, fontFamily: 'Poppins', color: Colors.white70),
displayLarge: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold, color: Colors.white),
titleLarge: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w500, color: Colors.white),
bodyMedium: TextStyle(fontSize: 14.0, fontFamily: 'Poppins', color: Colors.white70),
),
colorScheme: const ColorScheme.dark(
primary: Colors.white,
Expand Down Expand Up @@ -89,12 +125,9 @@ class ThemeProvider with ChangeNotifier {
cardColor: Colors.grey[100],
fontFamily: 'Poppins',
textTheme: const TextTheme(
displayLarge: TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold, color: Colors.black),
titleLarge: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.w500, color: Colors.black),
bodyMedium: TextStyle(
fontSize: 14.0, fontFamily: 'Poppins', color: Colors.black87),
displayLarge: TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold, color: Colors.black),
titleLarge: TextStyle(fontSize: 20.0, fontWeight: FontWeight.w500, color: Colors.black),
bodyMedium: TextStyle(fontSize: 14.0, fontFamily: 'Poppins', color: Colors.black87),
),
colorScheme: const ColorScheme.light(
primary: Colors.black,
Expand Down Expand Up @@ -177,10 +210,8 @@ void main() async {
final backupTaskLogProvider = BackupTaskLogProvider(authManager: authManager);
final lockProvider = LockProvider();
final remoteServerProvider = RemoteServerProvider(authManager: authManager);
final backupDestinationProvider =
BackupDestinationProvider(authManager: authManager);
final notificationStreamProvider =
NotificationStreamProvider(authManager: authManager);
final backupDestinationProvider = BackupDestinationProvider(authManager: authManager);
final notificationStreamProvider = NotificationStreamProvider(authManager: authManager);
final tagProvider = TagProvider(authManager: authManager);

await deviceInfoProvider.initializeDeviceInfo();
Expand Down Expand Up @@ -223,6 +254,7 @@ class MyApp extends StatelessWidget {
color: Colors.black,
theme: themeProvider.currentTheme,
home: LockScreen(
authManager: authManager, // Added authManager here
child: Consumer<UserProvider>(
builder: (context, userProvider, child) {
if (authManager.isLoggedIn && userProvider.user != null) {
Expand Down Expand Up @@ -308,14 +340,30 @@ class _MainNavigationWrapperState extends State<MainNavigationWrapper> {
fontWeight: FontWeight.w500,
),
),
IconButton(
PopupMenuButton<ThemeMode>(
icon: Icon(
themeProvider.isDarkMode
? Icons.light_mode
: Icons.dark_mode,
themeProvider.themeMode == ThemeMode.auto
? Icons.brightness_auto
: (themeProvider.isDarkMode ? Icons.dark_mode : Icons.light_mode),
color: Colors.white,
),
onPressed: () => themeProvider.toggleTheme(),
onSelected: (ThemeMode result) {
themeProvider.setThemeMode(result);
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<ThemeMode>>[
const PopupMenuItem<ThemeMode>(
value: ThemeMode.light,
child: Text('Light Mode'),
),
const PopupMenuItem<ThemeMode>(
value: ThemeMode.dark,
child: Text('Dark Mode'),
),
const PopupMenuItem<ThemeMode>(
value: ThemeMode.auto,
child: Text('Auto Mode'),
),
],
),
],
),
Expand All @@ -332,4 +380,4 @@ class _MainNavigationWrapperState extends State<MainNavigationWrapper> {
},
);
}
}
}
2 changes: 0 additions & 2 deletions lib/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ class ProfilePage extends StatelessWidget {
user.accountSettings.language),
_buildSettingItem(context, HeroIcons.userCircle, 'Elevated Permissions',
user.accountSettings.isAdmin ? 'Yes' : 'No'),
_buildSettingItem(context, HeroIcons.codeBracket, 'GitHub Login',
user.accountSettings.githubLoginEnabled ? 'Enabled' : 'Disabled'),
_buildSettingItem(context, HeroIcons.envelope, 'Weekly Summary',
user.accountSettings.weeklySummaryEnabled ? 'Enabled' : 'Disabled'),
],
Expand Down
Loading

0 comments on commit 4267ba0

Please sign in to comment.