Skip to content

Commit

Permalink
Fix light mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGuyDangerous committed Oct 7, 2024
1 parent 98d618f commit 967923c
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 151 deletions.
284 changes: 162 additions & 122 deletions lib/screens/settings/settings_screen_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,145 +133,185 @@ class SettingsScreenState extends State<SettingsScreen> {

@override
Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);

return Scaffold(
appBar: AppBar(
title: Text('Settings',
style:
TextStyle(fontFamily: 'Raleway', fontWeight: FontWeight.bold)),
),
body: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('API Keys', style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 16),
ApiKeyInput(
label: 'Brave Search API Key',
controller: _braveApiController,
icon: Iconsax.search_normal,
),
ApiKeyInput(
label: 'Groq API Key',
controller: _groqApiController,
icon: Iconsax.code,
),
SizedBox(height: 24),
Text('Privacy', style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 16),
SettingsSwitch(
title: 'Incognito Mode',
subtitle: 'Disable search history',
value: _isIncognitoMode,
onChanged: (value) {
setState(() {
_isIncognitoMode = value;
});
},
),
SizedBox(height: 24),
Text('Speech Recognition',
style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 16),
SettingsSwitch(
title: 'Use OpenAI Whisper Model',
subtitle: 'For improved speech recognition',
value: _useWhisperModel,
onChanged: (value) {
setState(() {
_useWhisperModel = value;
});
},
trailing: IconButton(
icon: Icon(Iconsax.info_circle, color: Colors.white70),
onPressed: _showWhisperInfoDialog,
),
),
SizedBox(height: 24),
SettingsSwitch(
title: 'Dark Mode',
subtitle: 'Toggle dark/light theme',
value: themeProvider.isDarkMode,
onChanged: (value) {
themeProvider.toggleTheme();
},
),
SizedBox(height: 24),
ElevatedButton(
onPressed: _isValidating ? null : _validateApiKeys,
child: Container(
width: double.infinity,
child: Center(
return Consumer<ThemeProvider>(
builder: (context, themeProvider, child) {
return Scaffold(
appBar: AppBar(
title: Text('Settings',
style: TextStyle(
fontFamily: 'Raleway', fontWeight: FontWeight.bold)),
),
body: SingleChildScrollView(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('API Keys',
style: TextStyle(
color: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold)),
SizedBox(height: 16),
ApiKeyInput(
label: 'Brave Search API Key',
controller: _braveApiController,
icon: Iconsax.search_normal,
),
ApiKeyInput(
label: 'Groq API Key',
controller: _groqApiController,
icon: Iconsax.code,
),
SizedBox(height: 24),
Text('Privacy',
style: TextStyle(
color: Theme.of(context).brightness == Brightness.dark
? Colors.white70
: Colors.grey[600],
fontSize: 18,
fontWeight: FontWeight.bold)),
SizedBox(height: 16),
SettingsSwitch(
isDarkMode: Theme.of(context).brightness == Brightness.dark,
title: 'Incognito Mode',
subtitle: 'Disable search history',
value: _isIncognitoMode,
onChanged: (value) {
setState(() {
_isIncognitoMode = value;
});
},
),
SizedBox(height: 24),
Text('Speech Recognition',
style: TextStyle(
color: Theme.of(context).brightness == Brightness.dark
? Colors.white70
: Colors.grey[600],
fontSize: 18,
fontWeight: FontWeight.bold)),
SizedBox(height: 16),
SettingsSwitch(
title: 'Use OpenAI Whisper Model',
subtitle: 'For improved speech recognition',
value: _useWhisperModel,
onChanged: (value) {
setState(() {
_useWhisperModel = value;
});
},
trailing: IconButton(
icon: Icon(Iconsax.info_circle,
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[600]
: Colors.black),
onPressed: _showWhisperInfoDialog,
),
isDarkMode: Theme.of(context).brightness == Brightness.dark,
),
SizedBox(height: 24),
SettingsSwitch(
isDarkMode: Theme.of(context).brightness == Brightness.dark,
title: 'Dark Mode',
subtitle: 'Toggle dark/light theme',
value: themeProvider.isDarkMode,
onChanged: (value) {
themeProvider.toggleTheme();
},
),
SizedBox(height: 24),
ElevatedButton(
onPressed: _isValidating ? null : _validateApiKeys,
child: _isValidating
? SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
color: Colors.white,
color: Colors.grey[600],
strokeWidth: 2,
),
)
: Text('Validate and Save Settings'),
style: ElevatedButton.styleFrom(
backgroundColor: themeProvider.isDarkMode
? Colors.grey[800]
: Colors.grey[800],
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 32, vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
minimumSize:
Size(double.infinity, 50), // Ensure consistent height
),
),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.grey[800],
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 32, vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
SizedBox(height: 32),
Text('About',
style: TextStyle(
color: themeProvider.isDarkMode
? Colors.white
: Colors.black,
fontSize: 18,
fontWeight: FontWeight.bold)),
SizedBox(height: 16),
ListTile(
leading: Icon(Iconsax.info_circle,
color: themeProvider.isDarkMode
? Colors.white70
: Colors.grey[600]),
title: Text('Version'),
subtitle: Text(AppConstants.appVersion),
),
minimumSize:
Size(double.infinity, 50), // Ensure consistent height
),
),
SizedBox(height: 32),
Text('About', style: Theme.of(context).textTheme.titleLarge),
SizedBox(height: 16),
ListTile(
leading: Icon(Iconsax.info_circle, color: Colors.white70),
title: Text('Version'),
subtitle: Text(AppConstants.appVersion),
),
ListTile(
leading: Icon(Iconsax.document, color: Colors.white70),
title: Text('License'),
subtitle: Text('Custom License'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => LicenseScreen()),
);
},
),
ListTile(
leading: Icon(Iconsax.code, color: Colors.white70),
title: Text('Source Code'),
subtitle: Text('GitHub'),
onTap: () => _launchURL(AppConstants.githubUrl),
),
SizedBox(height: 32),
Center(
child: Text(
'Created with ❣️ by Sannidhya Dubey',
style: TextStyle(
fontFamily: 'Raleway',
color: Colors.white70,
fontSize: 14,
ListTile(
leading: Icon(Iconsax.document,
color: themeProvider.isDarkMode
? Colors.white70
: Colors.grey[600]),
title: Text('License'),
subtitle: Text('Custom License'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => LicenseScreen()),
);
},
),
ListTile(
leading: Icon(Iconsax.code,
color: themeProvider.isDarkMode
? Colors.white70
: Colors.grey[600]),
title: Text('Source Code'),
subtitle: Text('GitHub'),
onTap: () => _launchURL(AppConstants.githubUrl),
),
SizedBox(height: 32),
Center(
child: Text(
'Created with ❣️ by Sannidhya Dubey',
style: TextStyle(
fontFamily: 'Raleway',
color: themeProvider.isDarkMode
? Colors.white70
: Colors.grey[600],
fontSize: 14,
),
),
),
),
],
),
],
),
),
),
);
},
);
}

Future<void> _launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
Fluttertoast.showToast(msg: "Could not launch $url");
}
Expand Down
50 changes: 27 additions & 23 deletions lib/widgets/library/history_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ class HistoryList extends StatelessWidget {
itemCount: searchHistory.length + 1,
separatorBuilder: (context, index) {
if (index == 0) return SizedBox.shrink();
return Divider(color: Colors.grey[800], height: 1, thickness: 0.5);
return Divider(
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[800]
: Colors.grey[200],
height: 1,
thickness: 0.5,
);
},
itemBuilder: (context, index) {
if (index == 0) {
Expand Down Expand Up @@ -97,7 +103,9 @@ class HistoryList extends StatelessWidget {
onItemTap(item['query']);
},
child: Card(
color: Colors.black,
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[900]
: Colors.grey[100], // Make the container transparent
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
Expand All @@ -106,33 +114,29 @@ class HistoryList extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
item['query'],
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 16,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Text(
_formatTimestamp(item['timestamp']),
style: TextStyle(color: Colors.white60, fontSize: 12),
),
],
Text(
item['query'],
style: TextStyle(
color: Theme.of(context).brightness == Brightness.dark
? Colors.white
: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 16,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 8),
Text(
item['summary'] != null
? _truncateSummary(item['summary'])
: 'No summary available',
style: TextStyle(color: Colors.white70, fontSize: 14),
style: TextStyle(
color: Theme.of(context).brightness == Brightness.dark
? Colors.white70
: Colors.black87,
fontSize: 14,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/settings/api_key_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class ApiKeyInput extends StatelessWidget {
return Container(
margin: EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
color: Colors.grey[900],
color: Theme.of(context).brightness == Brightness.dark
? Colors.grey[900]
: Colors.grey[800],
borderRadius: BorderRadius.circular(12),
),
child: ListTile(
Expand Down
Loading

0 comments on commit 967923c

Please sign in to comment.