Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding light mode toggle #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hacktoberxmlsa_app/providers/theme_provider.dart';
import 'package:hacktoberxmlsa_app/providers/userProfile.dart';
import 'package:hacktoberxmlsa_app/services/colors.dart';
import 'package:hacktoberxmlsa_app/theme.dart';
import 'package:hacktoberxmlsa_app/views/homePage.dart';
import 'package:hacktoberxmlsa_app/views/splashScreen.dart';
import 'package:provider/provider.dart';
Expand All @@ -14,6 +16,7 @@ void main() {
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => ThemeProvider()),
ChangeNotifierProvider(create: (_) => UserProfileProvider()),
],
child: MyApp(),
Expand All @@ -26,18 +29,18 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
final ThemeData systemDarkTheme = ThemeData.dark();

return MaterialApp(
debugShowCheckedModeBanner: false,
theme: systemDarkTheme.copyWith(
primaryColor: primaryColorDark,
),
initialRoute: '/splash',
routes: {
'/': (context) => const HomePage(),
'/splash': (context) => SplashScreen(),
},
);
return Consumer<ThemeProvider>(builder: (context, themeProvider, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: lightTheme,
darkTheme: darkTheme,
themeMode: themeProvider.currentTheme,
initialRoute: '/splash',
routes: {
'/': (context) => const HomePage(),
'/splash': (context) => SplashScreen(),
},
);
});
}
}
15 changes: 15 additions & 0 deletions lib/providers/theme_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';

class ThemeProvider extends ChangeNotifier {
bool _isLightTheme = true;

bool get isLightTheme => _isLightTheme;

ThemeMode get currentTheme =>
_isLightTheme ? ThemeMode.light : ThemeMode.dark;

void toggleTheme() {
_isLightTheme = !_isLightTheme;
notifyListeners();
}
}
21 changes: 21 additions & 0 deletions lib/theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/material.dart';

final ThemeData lightTheme = ThemeData(
primaryColor: Colors.blue,
scaffoldBackgroundColor: Colors.white,
brightness: Brightness.light,
appBarTheme: AppBarTheme(
color: Colors.blue,
iconTheme: IconThemeData(color: Colors.white),
),
);

final ThemeData darkTheme = ThemeData(
primaryColor: Colors.black,
scaffoldBackgroundColor: Colors.grey[900],
brightness: Brightness.dark,
appBarTheme: AppBarTheme(
color: Colors.black,
iconTheme: IconThemeData(color: Colors.white),
),
);
42 changes: 33 additions & 9 deletions lib/views/homePage.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:hacktoberxmlsa_app/providers/theme_provider.dart';
import 'package:hacktoberxmlsa_app/services/colors.dart';
import 'package:hacktoberxmlsa_app/views/noteCard.dart';
import 'package:hacktoberxmlsa_app/views/notePage.dart';
import 'package:hacktoberxmlsa_app/views/profile.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
const HomePage({super.key});
Expand Down Expand Up @@ -37,18 +39,32 @@ class _HomePageState extends State<HomePage> {
),
GestureDetector(
onTap: () {
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) {
return ProfilePage();
}));
},
child: CircleAvatar(
foregroundImage: NetworkImage('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRnDNmpgYnTP4ELmIob69uKE1O0Rbrotna00g&s'),
foregroundImage: NetworkImage(
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRnDNmpgYnTP4ELmIob69uKE1O0Rbrotna00g&s'),
radius: screenWidth * 0.05,
),
),
],
),
),
actions: [
IconButton(
icon: Icon(
Provider.of<ThemeProvider>(context).isLightTheme
? Icons.light_mode
: Icons.dark_mode,
),
onPressed: () {
Provider.of<ThemeProvider>(context, listen: false).toggleTheme();
},
),
],
),
body: Stack(
children: [
Expand All @@ -68,7 +84,8 @@ class _HomePageState extends State<HomePage> {
},
decoration: InputDecoration(
filled: false,
contentPadding: EdgeInsets.symmetric(vertical: 10, horizontal: 20),
contentPadding:
EdgeInsets.symmetric(vertical: 10, horizontal: 20),
labelStyle: TextStyle(
color: Colors.white,
),
Expand All @@ -78,7 +95,9 @@ class _HomePageState extends State<HomePage> {
borderSide: BorderSide(width: 2, color: purple),
),
hintText: 'Search your notes here',
hintStyle: TextStyle(color: Colors.white60, fontWeight: FontWeight.normal)),
hintStyle: TextStyle(
color: Colors.white60,
fontWeight: FontWeight.normal)),
),
SizedBox(
height: screenHeight * 0.02,
Expand All @@ -102,14 +121,16 @@ class _HomePageState extends State<HomePage> {
padding: const EdgeInsets.all(8.0),
child: NoteCard(
noteTitle: 'Note ${index + 1}',
noteContent: 'This is the content of note ${index + 1}',
noteContent:
'This is the content of note ${index + 1}',
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NotePage(
title: 'Note ${index + 1}',
content: 'This is the content of note ${index + 1}',
content:
'This is the content of note ${index + 1}',
)));
}),
);
Expand Down Expand Up @@ -141,11 +162,13 @@ class _HomePageState extends State<HomePage> {
MaterialPageRoute(
builder: (context) => NotePage(
title: 'Note ${index + 1}',
content: 'This is the content of note ${index + 1}',
content:
'This is the content of note ${index + 1}',
)));
},
noteTitle: 'Quick Note ${index + 1}',
noteContent: 'This is a quick note. Content preview for note ${index + 1}.',
noteContent:
'This is a quick note. Content preview for note ${index + 1}.',
);
},
),
Expand All @@ -169,7 +192,8 @@ class _HomePageState extends State<HomePage> {
right: screenWidth * 0.05,
child: FloatingActionButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => NotePage()));
Navigator.push(context,
MaterialPageRoute(builder: (context) => NotePage()));
},
child: Icon(Icons.add),
backgroundColor: purple,
Expand Down
39 changes: 20 additions & 19 deletions lib/views/notePage.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flutter/material.dart';
import 'package:hacktoberxmlsa_app/providers/theme_provider.dart';
import 'package:hacktoberxmlsa_app/views/homePage.dart';
import 'package:hacktoberxmlsa_app/views/intivePopPage.dart';
import 'package:provider/provider.dart';

class NotePage extends StatefulWidget {

final String? title;
final String? content;

Expand All @@ -14,13 +15,12 @@ class NotePage extends StatefulWidget {
}

class _NotePageState extends State<NotePage> {

late TextEditingController titleController;
late TextEditingController contentController;

FocusNode noteFocus = FocusNode();

@override
@override
void initState() {
super.initState();
titleController = TextEditingController(text: widget.title ?? '');
Expand All @@ -34,7 +34,7 @@ class _NotePageState extends State<NotePage> {
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
},
icon: Icon(Icons.arrow_back_ios_new_rounded),
),
actions: [
Expand All @@ -44,8 +44,17 @@ class _NotePageState extends State<NotePage> {
},
icon: const Icon(Icons.more_horiz_rounded),
),
IconButton(
icon: Icon(
Provider.of<ThemeProvider>(context).isLightTheme
? Icons.light_mode
: Icons.dark_mode,
),
onPressed: () {
Provider.of<ThemeProvider>(context, listen: false).toggleTheme();
},
),
],

),
body: SafeArea(
child: Padding(
Expand All @@ -57,27 +66,19 @@ class _NotePageState extends State<NotePage> {
children: [
TextField(
controller: titleController,
style: const TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold
),
style:
const TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
decoration: const InputDecoration(
hintText: "Title",
border: InputBorder.none
),
hintText: "Title", border: InputBorder.none),
),
Expanded(
child: TextField(
controller: contentController,
focusNode: noteFocus,
maxLines: null,
style: const TextStyle(
fontSize: 20
),
style: const TextStyle(fontSize: 20),
decoration: const InputDecoration(
hintText: "Note",
border: InputBorder.none
),
hintText: "Note", border: InputBorder.none),
),
),
],
Expand All @@ -86,4 +87,4 @@ class _NotePageState extends State<NotePage> {
),
);
}
}
}
15 changes: 11 additions & 4 deletions lib/views/profile.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:hacktoberxmlsa_app/providers/theme_provider.dart';
import 'package:hacktoberxmlsa_app/providers/userProfile.dart';
import 'package:hacktoberxmlsa_app/services/colors.dart';
import 'package:hacktoberxmlsa_app/utils/auth_utils.dart';
import 'package:hacktoberxmlsa_app/views/homePage.dart';
import 'package:hacktoberxmlsa_app/widgets/button.dart';
import 'package:hacktoberxmlsa_app/widgets/textfield.dart';
import 'package:provider/provider.dart';
import 'package:image_picker/image_picker.dart';
import 'package:image_picker/image_picker.dart';

class ProfilePage extends StatefulWidget {
const ProfilePage({super.key});
Expand Down Expand Up @@ -67,7 +68,7 @@ class _ProfilePageState extends State<ProfilePage> {
@override
Widget build(BuildContext context) {
final userProfile = Provider.of<UserProfileProvider>(context);

double screenWidth = MediaQuery.of(context).size.width;
double screenHeight = MediaQuery.of(context).size.height;

Expand All @@ -82,8 +83,14 @@ class _ProfilePageState extends State<ProfilePage> {
),
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.light_mode),
onPressed: () {
Provider.of<ThemeProvider>(context, listen: false).toggleTheme();
},
icon: Icon(
Provider.of<ThemeProvider>(context).isLightTheme
? Icons.light_mode
: Icons.dark_mode,
),
),
],
),
Expand Down