Skip to content

Commit

Permalink
Merge pull request #422 from jaivsh/ninth
Browse files Browse the repository at this point in the history
Added Light theme in app
  • Loading branch information
avinashkranjan authored Aug 10, 2023
2 parents cc1677a + ab40f8a commit f6bba73
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
19 changes: 11 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:flutter/material.dart';
import 'package:friday/feedback.dart';
import 'package:friday/screens/theme_screen.dart';
import 'package:friday/services/phone_number_verification_db.dart';
import 'package:friday/services/theme_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:friday/screens/phone_verification_screen.dart';
import 'package:friday/screens/verify_code_screen.dart';
Expand All @@ -38,7 +39,14 @@ void main() async {
NotificationService().initNotification();
NotificationService().showNotification(title: 'olalalaaa', body: 'it works');
await Firebase.initializeApp();
runApp(MyApp());
runApp(MultiProvider( // create the provider
providers: [
ChangeNotifierProvider(
create: (_) => ThemeProvider(),
)
],
child: MyApp(),
),);
}

class MyApp extends StatefulWidget {
Expand Down Expand Up @@ -126,6 +134,7 @@ class _MyAppState extends State<MyApp> {
child: WillPopScope(
onWillPop:onWillPop,
child: MaterialApp(
theme: Provider.of<ThemeProvider>(context).currentTheme,
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
Expand All @@ -142,13 +151,7 @@ class _MyAppState extends State<MyApp> {
],
debugShowCheckedModeBanner: false,
title: 'Friday',
theme: ThemeData(
primaryColor: Color(0xFF202328),
visualDensity: VisualDensity.adaptivePlatformDensity,
colorScheme: ColorScheme.fromSwatch()
.copyWith(secondary: Color(0xFF651FFF))
.copyWith(background: Color(0xFF12171D)),
),

home: FutureBuilder(
future: Future.delayed(Duration(seconds: 3)),
builder: (context, snapshot) {
Expand Down
12 changes: 8 additions & 4 deletions lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:open_url/open_url.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import '../models/users.dart';
import '../services/theme_provider.dart';
import '../services/user_info_services.dart';
import 'package:settings_ui/settings_ui.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
Expand All @@ -22,6 +23,7 @@ class SettingsScreen extends StatefulWidget {
class _SettingsScreenState extends State<SettingsScreen> {
get visibilityName => null;
bool modeval = false;

late bool? notification;
ThemeData? _currentTheme;

Expand Down Expand Up @@ -131,18 +133,20 @@ class _SettingsScreenState extends State<SettingsScreen> {
title: Text(AppLocalizations.of(context).language),
value: Text('English'),
),
SettingsTile.switchTile(initialValue: ThemeMode.system == ThemeMode.light ? !modeval : modeval, onToggle: (s) {
SettingsTile.switchTile(initialValue: modeval, onToggle: (s) {
final themeProvider =
Provider.of<ThemeProvider>(context, listen: false);
setState(() {
modeval = s;
});
if(modeval) {
setState(() {
_setTheme(lightTheme);
themeProvider.setLightMode();
});
}
else {
setState(() {
_setTheme(darkTheme);
themeProvider.setDarkmode();
});
}

Expand Down Expand Up @@ -230,4 +234,4 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
);
}
}
}
7 changes: 4 additions & 3 deletions lib/screens/themes.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'package:flutter/material.dart';



final lightTheme = ThemeData(
brightness: Brightness.light,
visualDensity: VisualDensity.adaptivePlatformDensity,
colorScheme: ColorScheme.fromSwatch()

.copyWith(secondary: Colors.white)
.copyWith(primary: Colors.black),

);

final darkTheme = ThemeData(

primaryColor: Color(0xFF202328),
visualDensity: VisualDensity.adaptivePlatformDensity,
colorScheme: ColorScheme.fromSwatch()
Expand Down
17 changes: 17 additions & 0 deletions lib/services/theme_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';

import '../screens/themes.dart';

class ThemeProvider extends ChangeNotifier {
ThemeData? currentTheme;

setLightMode() {
currentTheme = lightTheme;
notifyListeners();
}

setDarkmode() {
currentTheme = darkTheme;
notifyListeners();
}
}

0 comments on commit f6bba73

Please sign in to comment.