Commit 5d558f83 authored by ayodyabanuka's avatar ayodyabanuka

dark mode added

parent 406e76f6
......@@ -6,7 +6,9 @@ import 'package:flutter/services.dart';
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
import 'package:ifarm/AB/Screens/FoodBucket/SingleFoodBucketData.dart';
import 'package:ifarm/AB/Utils/Colors.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:ifarm/functions/firebaseFunctions.dart';
import 'package:provider/provider.dart';
class foodbuckets extends StatefulWidget {
foodbuckets({Key key}) : super(key: key);
......@@ -29,13 +31,14 @@ class _foodbucketsState extends State<foodbuckets> {
@override
Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);
final Stream<QuerySnapshot> bucketref =
FirebaseFirestore.instance.collection('buckets').snapshots();
return Scaffold(
backgroundColor: const Color(0xff024F8E),
appBar: AppBar(
backgroundColor: const Color(0xff024F8E),
backgroundColor:
themeProvider.isDarkMode ? backgroundColor : backgroundColorDark,
elevation: 0,
),
body: Container(
......@@ -43,12 +46,17 @@ class _foodbucketsState extends State<foodbuckets> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Food',
const SizedBox(
height: 20,
),
const Center(
child: Text(
'Your Food Bucket list',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 40),
fontSize: 20),
),
),
const SizedBox(
height: 20,
......@@ -76,7 +84,7 @@ class _foodbucketsState extends State<foodbuckets> {
child: Text(
'Add bucket',
style: TextStyle(
color: Colors.white,
color: textColor,
fontSize: 20,
fontWeight: FontWeight.bold),
))
......@@ -109,21 +117,17 @@ class _foodbucketsState extends State<foodbuckets> {
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(
'Bucket :',
style: TextStyle(
color: Colors.black,
Text(
'Bucket ${storedata[0]['Buckets'][index]} ',
style: const TextStyle(
color: textColor,
fontSize: 20,
fontWeight: FontWeight.bold),
),
Text(storedata[0]['Buckets'][index],
style: const TextStyle(
color: Colors.black,
fontSize: 15))
]),
const Icon(
Icons.arrow_right,
color: Colors.black,
color: textColor,
)
],
),
......@@ -139,10 +143,11 @@ class _foodbucketsState extends State<foodbuckets> {
onPressed: () {
scanQRCode();
},
backgroundColor: Colors.white,
backgroundColor: themeProvider.isDarkMode
? naviconUnselectedColor
: naviconUnselectedColorDark,
child: const Icon(
Icons.add,
color: Color(0xff024F8E),
),
),
);
......
import 'dart:async';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
......@@ -61,7 +59,6 @@ class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: backgroundColor,
body: Container(
margin: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
......
......@@ -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/settings.dart';
import 'package:ifarm/AB/Utils/Colors.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:provider/provider.dart';
class Navbar extends StatefulWidget {
Navbar({
......@@ -20,8 +22,8 @@ class _NavbarState extends State<Navbar> {
@override
Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);
return Scaffold(
backgroundColor: backgroundColor,
appBar: AppBar(
title: const SizedBox(
width: 100,
......@@ -44,12 +46,17 @@ class _NavbarState extends State<Navbar> {
],
),
bottomNavigationBar: BottomNavigationBar(
backgroundColor: const Color.fromARGB(150, 6, 91, 161),
backgroundColor:
themeProvider.isDarkMode ? backgroundColor : backgroundColorDark,
type: BottomNavigationBarType.fixed,
elevation: 1,
currentIndex: _selectedIndex,
selectedItemColor: Colors.white,
unselectedItemColor: Colors.grey,
selectedItemColor: themeProvider.isDarkMode
? naviconSelectedColor
: naviconSelectedColorDark,
unselectedItemColor: themeProvider.isDarkMode
? naviconUnselectedColor
: naviconUnselectedColorDark,
showSelectedLabels: false,
showUnselectedLabels: false,
items: const [
......
import 'package:firebase_auth/firebase_auth.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:switcher_button/switcher_button.dart';
import '../Common/SplashScreen.dart';
class settings extends StatefulWidget {
......@@ -16,19 +14,7 @@ class settings extends StatefulWidget {
State<settings> createState() => _settingsState();
}
bool foodswitch = false;
bool waterswitch = false;
bool environmentswitch = false;
bool securityswitch = false;
class _settingsState extends State<settings> {
@override
void initState() {
getdata();
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
......@@ -49,115 +35,18 @@ class _settingsState extends State<settings> {
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
children: const [
Expanded(
child: Text(
'Theme',
style: TextStyle(color: Colors.white, fontSize: 17),
)),
// Switch(
// value: _themeManager.themeMode == ThemeMode.dark,
// onChanged: (value) {
// _themeManager.toggleTheme(value);
// })
ChangeThemeButtonWidget(),
],
),
const SizedBox(
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(
height: 40,
),
......@@ -177,7 +66,7 @@ class _settingsState extends State<settings> {
child: Container(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 20),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(15)),
color: cardColor, borderRadius: BorderRadius.circular(15)),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
......@@ -185,11 +74,11 @@ class _settingsState extends State<settings> {
Expanded(
child: Text(
'Logout',
style: TextStyle(color: Colors.black, fontSize: 17),
style: TextStyle(color: textColor, fontSize: 17),
)),
Icon(
Icons.logout,
color: Colors.red,
color: naviconSelectedColor,
)
],
),
......@@ -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);
const backgroundColorDark = Color.fromARGB(255, 27, 27, 27);
const cardColor = Color.fromARGB(54, 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 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 blacktxtColor = Color.fromARGB(255, 0, 0, 0);
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:ifarm/AB/Utils/Colors.dart';
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(
scaffoldBackgroundColor: backgroundColor,
colorScheme: const ColorScheme.light(
primary: backgroundColor,
class MyThemes {
static final lightTheme = ThemeData(
primaryColor: backgroundColor,
brightness: Brightness.light,
));
ThemeData darkTheme = ThemeData(
scaffoldBackgroundColor: backgroundColorDark,
colorScheme: const ColorScheme.dark(
primary: backgroundColorDark,
scaffoldBackgroundColor: backgroundColor,
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: naviconUnselectedColor),
appBarTheme:
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,
));
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:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:provider/provider.dart';
import 'package:switcher_button/switcher_button.dart';
class ChangeThemeButtonWidget extends StatelessWidget {
const ChangeThemeButtonWidget({Key key}) : super(key: key);
@override
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';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ifarm/AB/Utils/ThemeProvider.dart';
import 'package:provider/provider.dart';
import 'AB/Screens/Common/SplashScreen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
runApp(const MyApp());
}
......@@ -17,14 +23,18 @@ class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
Widget build(BuildContext context) => ChangeNotifierProvider(
create: (context) => ThemeProvider(),
builder: (context, _) {
final themeProvider = Provider.of<ThemeProvider>(context);
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'IFarm',
theme: lightTheme,
darkTheme: darkTheme,
themeMode: ThemeMode.system,
theme: MyThemes.lightTheme,
darkTheme: MyThemes.darkTheme,
themeMode: themeProvider.themeMode,
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