Commit 5d558f83 authored by ayodyabanuka's avatar ayodyabanuka

dark mode added

parent 406e76f6
...@@ -6,7 +6,9 @@ import 'package:flutter/services.dart'; ...@@ -6,7 +6,9 @@ import 'package:flutter/services.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart'; import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
import 'package:ifarm/AB/Screens/FoodBucket/SingleFoodBucketData.dart'; import 'package:ifarm/AB/Screens/FoodBucket/SingleFoodBucketData.dart';
import 'package:ifarm/AB/Utils/Colors.dart'; import 'package:ifarm/AB/Utils/Colors.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:ifarm/functions/firebaseFunctions.dart'; import 'package:ifarm/functions/firebaseFunctions.dart';
import 'package:provider/provider.dart';
class foodbuckets extends StatefulWidget { class foodbuckets extends StatefulWidget {
foodbuckets({Key key}) : super(key: key); foodbuckets({Key key}) : super(key: key);
...@@ -29,13 +31,14 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -29,13 +31,14 @@ class _foodbucketsState extends State<foodbuckets> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);
final Stream<QuerySnapshot> bucketref = final Stream<QuerySnapshot> bucketref =
FirebaseFirestore.instance.collection('buckets').snapshots(); FirebaseFirestore.instance.collection('buckets').snapshots();
return Scaffold( return Scaffold(
backgroundColor: const Color(0xff024F8E),
appBar: AppBar( appBar: AppBar(
backgroundColor: const Color(0xff024F8E), backgroundColor:
themeProvider.isDarkMode ? backgroundColor : backgroundColorDark,
elevation: 0, elevation: 0,
), ),
body: Container( body: Container(
...@@ -43,12 +46,17 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -43,12 +46,17 @@ class _foodbucketsState extends State<foodbuckets> {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const Text( const SizedBox(
'Food', height: 20,
),
const Center(
child: Text(
'Your Food Bucket list',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 40), fontSize: 20),
),
), ),
const SizedBox( const SizedBox(
height: 20, height: 20,
...@@ -76,7 +84,7 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -76,7 +84,7 @@ class _foodbucketsState extends State<foodbuckets> {
child: Text( child: Text(
'Add bucket', 'Add bucket',
style: TextStyle( style: TextStyle(
color: Colors.white, color: textColor,
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.bold), fontWeight: FontWeight.bold),
)) ))
...@@ -109,21 +117,17 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -109,21 +117,17 @@ class _foodbucketsState extends State<foodbuckets> {
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment.start, CrossAxisAlignment.start,
children: [ children: [
const Text( Text(
'Bucket :', 'Bucket ${storedata[0]['Buckets'][index]} ',
style: TextStyle( style: const TextStyle(
color: Colors.black, color: textColor,
fontSize: 20, fontSize: 20,
fontWeight: FontWeight.bold), fontWeight: FontWeight.bold),
), ),
Text(storedata[0]['Buckets'][index],
style: const TextStyle(
color: Colors.black,
fontSize: 15))
]), ]),
const Icon( const Icon(
Icons.arrow_right, Icons.arrow_right,
color: Colors.black, color: textColor,
) )
], ],
), ),
...@@ -139,10 +143,11 @@ class _foodbucketsState extends State<foodbuckets> { ...@@ -139,10 +143,11 @@ class _foodbucketsState extends State<foodbuckets> {
onPressed: () { onPressed: () {
scanQRCode(); scanQRCode();
}, },
backgroundColor: Colors.white, backgroundColor: themeProvider.isDarkMode
? naviconUnselectedColor
: naviconUnselectedColorDark,
child: const Icon( child: const Icon(
Icons.add, Icons.add,
color: Color(0xff024F8E),
), ),
), ),
); );
......
import 'dart:async';
import 'package:firebase_database/firebase_database.dart'; import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
...@@ -61,7 +59,6 @@ class _HomeState extends State<Home> { ...@@ -61,7 +59,6 @@ class _HomeState extends State<Home> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: backgroundColor,
body: Container( body: Container(
margin: const EdgeInsets.symmetric(horizontal: 15), margin: const EdgeInsets.symmetric(horizontal: 15),
child: Column( child: Column(
......
...@@ -5,6 +5,8 @@ import 'package:ifarm/AB/Screens/NavBar/Home.dart'; ...@@ -5,6 +5,8 @@ import 'package:ifarm/AB/Screens/NavBar/Home.dart';
import 'package:ifarm/AB/Screens/NavBar/Profile.dart'; import 'package:ifarm/AB/Screens/NavBar/Profile.dart';
import 'package:ifarm/AB/Screens/NavBar/settings.dart'; import 'package:ifarm/AB/Screens/NavBar/settings.dart';
import 'package:ifarm/AB/Utils/Colors.dart'; import 'package:ifarm/AB/Utils/Colors.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:provider/provider.dart';
class Navbar extends StatefulWidget { class Navbar extends StatefulWidget {
Navbar({ Navbar({
...@@ -20,8 +22,8 @@ class _NavbarState extends State<Navbar> { ...@@ -20,8 +22,8 @@ class _NavbarState extends State<Navbar> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);
return Scaffold( return Scaffold(
backgroundColor: backgroundColor,
appBar: AppBar( appBar: AppBar(
title: const SizedBox( title: const SizedBox(
width: 100, width: 100,
...@@ -44,12 +46,17 @@ class _NavbarState extends State<Navbar> { ...@@ -44,12 +46,17 @@ class _NavbarState extends State<Navbar> {
], ],
), ),
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
backgroundColor: const Color.fromARGB(150, 6, 91, 161), backgroundColor:
themeProvider.isDarkMode ? backgroundColor : backgroundColorDark,
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
elevation: 1, elevation: 1,
currentIndex: _selectedIndex, currentIndex: _selectedIndex,
selectedItemColor: Colors.white, selectedItemColor: themeProvider.isDarkMode
unselectedItemColor: Colors.grey, ? naviconSelectedColor
: naviconSelectedColorDark,
unselectedItemColor: themeProvider.isDarkMode
? naviconUnselectedColor
: naviconUnselectedColorDark,
showSelectedLabels: false, showSelectedLabels: false,
showUnselectedLabels: false, showUnselectedLabels: false,
items: const [ items: const [
......
import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart'; import 'package:ifarm/AB/Utils/Colors.dart';
import 'package:ifarm/AB/widget/ChangeThemeButtonWidget.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:switcher_button/switcher_button.dart';
import '../Common/SplashScreen.dart'; import '../Common/SplashScreen.dart';
class settings extends StatefulWidget { class settings extends StatefulWidget {
...@@ -16,19 +14,7 @@ class settings extends StatefulWidget { ...@@ -16,19 +14,7 @@ class settings extends StatefulWidget {
State<settings> createState() => _settingsState(); State<settings> createState() => _settingsState();
} }
bool foodswitch = false;
bool waterswitch = false;
bool environmentswitch = false;
bool securityswitch = false;
class _settingsState extends State<settings> { class _settingsState extends State<settings> {
@override
void initState() {
getdata();
// TODO: implement initState
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
...@@ -49,115 +35,18 @@ class _settingsState extends State<settings> { ...@@ -49,115 +35,18 @@ class _settingsState extends State<settings> {
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: const [
const Expanded( Expanded(
child: Text( child: Text(
'Theme', 'Theme',
style: TextStyle(color: Colors.white, fontSize: 17), style: TextStyle(color: Colors.white, fontSize: 17),
)), )),
// Switch( ChangeThemeButtonWidget(),
// value: _themeManager.themeMode == ThemeMode.dark,
// onChanged: (value) {
// _themeManager.toggleTheme(value);
// })
], ],
), ),
const SizedBox( const SizedBox(
height: 40, height: 40,
), ),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
child: Text(
'Food Sensors',
style: TextStyle(color: Colors.white, fontSize: 17),
)),
SwitcherButton(
value: foodswitch,
onChange: (value) {
setState(() {
foodswitch = value;
save_datafood(value);
print(value);
});
},
)
],
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
child: Text(
'Water Sensors',
style: TextStyle(color: Colors.white, fontSize: 17),
)),
SwitcherButton(
value: waterswitch,
onChange: (value) {
setState(() {
waterswitch = value;
save_datawater(value);
print(value);
});
},
)
],
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
child: Text(
'Environment Sensors',
style: TextStyle(color: Colors.white, fontSize: 17),
)),
SwitcherButton(
value: environmentswitch,
onChange: (value) {
setState(() {
environmentswitch = value;
save_dataenv(value);
print(value);
});
},
)
],
),
const SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
child: Text(
'Security Sensors',
style: TextStyle(color: Colors.white, fontSize: 17),
)),
SwitcherButton(
value: securityswitch,
onChange: (value) {
setState(() {
securityswitch = value;
save_datasecurity(value);
print(value);
});
},
)
],
),
const SizedBox( const SizedBox(
height: 40, height: 40,
), ),
...@@ -177,7 +66,7 @@ class _settingsState extends State<settings> { ...@@ -177,7 +66,7 @@ class _settingsState extends State<settings> {
child: Container( child: Container(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 20), padding: EdgeInsets.symmetric(horizontal: 15, vertical: 20),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(15)), color: cardColor, borderRadius: BorderRadius.circular(15)),
child: Center( child: Center(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
...@@ -185,11 +74,11 @@ class _settingsState extends State<settings> { ...@@ -185,11 +74,11 @@ class _settingsState extends State<settings> {
Expanded( Expanded(
child: Text( child: Text(
'Logout', 'Logout',
style: TextStyle(color: Colors.black, fontSize: 17), style: TextStyle(color: textColor, fontSize: 17),
)), )),
Icon( Icon(
Icons.logout, Icons.logout,
color: Colors.red, color: naviconSelectedColor,
) )
], ],
), ),
...@@ -200,44 +89,4 @@ class _settingsState extends State<settings> { ...@@ -200,44 +89,4 @@ class _settingsState extends State<settings> {
), ),
); );
} }
void save_datafood(bool value) async {
SharedPreferences localStorage = await SharedPreferences.getInstance();
localStorage.setBool('food', value);
print('save');
}
void save_datawater(bool value) async {
SharedPreferences localStorage = await SharedPreferences.getInstance();
localStorage.setBool('water', value);
print('save');
}
void save_dataenv(bool value) async {
SharedPreferences localStorage = await SharedPreferences.getInstance();
localStorage.setBool('env', value);
print('save');
}
void save_datasecurity(bool value) async {
SharedPreferences localStorage = await SharedPreferences.getInstance();
localStorage.setBool('security', value);
print('save');
}
getdata() async {
print('login');
SharedPreferences localStorage = await SharedPreferences.getInstance();
var foodswitch1 = localStorage.getBool('food') as bool;
var waterswitch1 = localStorage.getBool('water') as bool;
var environmentswitch1 = localStorage.getBool('env') as bool;
var securityswitch1 = localStorage.getBool('security') as bool;
setState(() {
foodswitch = foodswitch1;
waterswitch1 = waterswitch1;
environmentswitch = environmentswitch1;
securityswitch = securityswitch1;
});
}
} }
...@@ -4,8 +4,10 @@ const backgroundColor = Color(0xff024F8E); ...@@ -4,8 +4,10 @@ const backgroundColor = Color(0xff024F8E);
const backgroundColorDark = Color.fromARGB(255, 27, 27, 27); const backgroundColorDark = Color.fromARGB(255, 27, 27, 27);
const cardColor = Color.fromARGB(54, 255, 255, 255); const cardColor = Color.fromARGB(54, 255, 255, 255);
const textColor = Color.fromARGB(255, 255, 255, 255); const textColor = Color.fromARGB(255, 255, 255, 255);
const subtextColor = Color.fromARGB(255, 223, 223, 223); const subtextColor = Color.fromARGB(255, 160, 160, 160);
const naviconSelectedColor = Color.fromARGB(255, 255, 255, 255); const naviconSelectedColor = Color.fromARGB(255, 255, 255, 255);
const naviconUnselectedColor = Color.fromARGB(255, 170, 170, 170); const naviconUnselectedColor = Color.fromARGB(255, 209, 209, 209);
const naviconSelectedColorDark = Color.fromARGB(255, 209, 209, 209);
const naviconUnselectedColorDark = Color.fromARGB(255, 63, 63, 63);
const yellowButton = Color(0xffFEC427); const yellowButton = Color(0xffFEC427);
const blacktxtColor = Color.fromARGB(255, 0, 0, 0); const blacktxtColor = Color.fromARGB(255, 0, 0, 0);
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:ifarm/AB/Utils/Colors.dart'; import 'package:ifarm/AB/Utils/Colors.dart';
class ThemeProvider with ChangeNotifier { class ThemeProvider with ChangeNotifier {
ThemeMode _themeMode = ThemeMode.light; ThemeMode themeMode = ThemeMode.light;
bool get themeMode => _themeMode == ThemeMode.light; bool get isDarkMode {
if (themeMode == ThemeMode.dark) {
final brightness = SchedulerBinding.instance.window.platformBrightness;
return brightness == Brightness.dark;
} else {
return themeMode == ThemeMode.light;
}
}
void toggleTheme(bool isOn) {
themeMode = isOn ? ThemeMode.dark : ThemeMode.light;
notifyListeners();
}
} }
ThemeData lightTheme = ThemeData( class MyThemes {
scaffoldBackgroundColor: backgroundColor, static final lightTheme = ThemeData(
colorScheme: const ColorScheme.light( primaryColor: backgroundColor,
primary: backgroundColor,
brightness: Brightness.light, brightness: Brightness.light,
)); scaffoldBackgroundColor: backgroundColor,
ThemeData darkTheme = ThemeData( floatingActionButtonTheme: FloatingActionButtonThemeData(
scaffoldBackgroundColor: backgroundColorDark, backgroundColor: naviconUnselectedColor),
colorScheme: const ColorScheme.dark( appBarTheme:
primary: backgroundColorDark, const AppBarTheme(backgroundColor: backgroundColor, elevation: 0),
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
backgroundColor: backgroundColor,
selectedItemColor: naviconSelectedColor,
unselectedItemColor: naviconUnselectedColor),
colorScheme: const ColorScheme.light());
static final darkTheme = ThemeData(
primaryColor: backgroundColorDark,
brightness: Brightness.dark, brightness: Brightness.dark,
)); floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: naviconUnselectedColorDark),
appBarTheme:
const AppBarTheme(backgroundColor: backgroundColorDark, elevation: 0),
scaffoldBackgroundColor: backgroundColorDark,
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
backgroundColor: backgroundColorDark,
selectedItemColor: naviconSelectedColor,
unselectedItemColor: naviconUnselectedColor),
colorScheme: const ColorScheme.dark());
}
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:provider/provider.dart';
import 'package:switcher_button/switcher_button.dart';
class ChangeThemeButtonWidget extends StatelessWidget { class ChangeThemeButtonWidget extends StatelessWidget {
const ChangeThemeButtonWidget({Key key}) : super(key: key); const ChangeThemeButtonWidget({Key key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container(); final themeProvider = Provider.of<ThemeProvider>(context);
return SwitcherButton(
value: !themeProvider.isDarkMode,
onChange: (value) {
final provider = Provider.of<ThemeProvider>(context, listen: false);
provider.toggleTheme(value);
},
);
} }
} }
...@@ -2,13 +2,19 @@ import 'dart:io'; ...@@ -2,13 +2,19 @@ import 'dart:io';
import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart'; import 'package:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:provider/provider.dart';
import 'AB/Screens/Common/SplashScreen.dart'; import 'AB/Screens/Common/SplashScreen.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(); await Firebase.initializeApp();
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
runApp(const MyApp()); runApp(const MyApp());
} }
...@@ -17,14 +23,18 @@ class MyApp extends StatelessWidget { ...@@ -17,14 +23,18 @@ class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key); const MyApp({Key key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) => ChangeNotifierProvider(
create: (context) => ThemeProvider(),
builder: (context, _) {
final themeProvider = Provider.of<ThemeProvider>(context);
return MaterialApp( return MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
title: 'IFarm', title: 'IFarm',
theme: lightTheme, theme: MyThemes.lightTheme,
darkTheme: darkTheme, darkTheme: MyThemes.darkTheme,
themeMode: ThemeMode.system, themeMode: themeProvider.themeMode,
home: splashScreen(), home: splashScreen(),
); );
} },
);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment