You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
diplomatic-quarter/lib/pages/settings/general_setting.dart

404 lines
14 KiB
Dart

import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/services/permission/permission_service.dart';
import 'package:diplomaticquarterapp/theme/theme_notifier.dart';
import 'package:diplomaticquarterapp/theme/theme_value.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:screen/screen.dart';
class GeneralSettings extends StatefulWidget {
@override
_GeneralSettings createState() => _GeneralSettings();
}
class _GeneralSettings extends State<GeneralSettings>
with TickerProviderStateMixin {
var themeNotifier;
var mediaQueryData;
int blindValue = 0;
bool vibration =false;
bool accsibility =false;
bool camera =false;
bool location =false;
var sharedPref = new AppSharedPreferences();
var permission = new PermissionService();
@override
void initState() {
getValues();
super.initState();
}
Widget build(BuildContext context) {
mediaQueryData = MediaQuery.of(context);
themeNotifier = Provider.of<ThemeNotifier>(context);
return Container(
child: ListView(scrollDirection: Axis.vertical, children: <Widget>[
Container(
padding: EdgeInsets.all(10),
child: AppText(
TranslationBase.of(context).modes,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).vibration),
Switch(
value: vibration,
onChanged: (value) {
setState(() {
vibration = value;
});
setVibration(value);
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
)
],
)),
Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).accessibility),
Switch(
value: accsibility,
onChanged: (value) {
setState(() {
accsibility = value;
});
permission.openSettings();
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
)
],
)),
// Container(
// padding: EdgeInsets.all(10),
// child: AppText(
// TranslationBase.of(context).blindMode,
// color: Colors.black,
// fontWeight: FontWeight.bold,
// ),
// ),
// new Container(
// color: Colors.white,
// padding: EdgeInsets.all(8.0),
// child: new Column(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// new Column(
// mainAxisAlignment: MainAxisAlignment.center,
// children: <Widget>[
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// new Text(
// TranslationBase.of(context).offTheme,
// style: new TextStyle(fontSize: 16.0),
// ),
// Radio(
// value: 0,
// groupValue: blindValue,
// onChanged: (value) {
// setState(() => {this.blindValue = value});
// setTheme(value);
// },
// ),
// ],
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// new Text(
// TranslationBase.of(context).invertTheme,
// style: new TextStyle(
// fontSize: 16.0,
// ),
// ),
// new Radio(
// value: 1,
// groupValue: blindValue,
// onChanged: (value) {
// setState(() => {this.blindValue = value});
// setTheme(value);
// },
// )
// ],
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// new Text(
// TranslationBase.of(context).dimTheme,
// style: new TextStyle(fontSize: 16.0),
// ),
// new Radio(
// value: 2,
// groupValue: blindValue,
// onChanged: (value) {
// setState(() => {this.blindValue = value});
// setTheme(value);
// },
// ),
// ],
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// new Text(
// TranslationBase.of(context).bwTheme,
// style: new TextStyle(fontSize: 16.0),
// ),
// new Radio(
// value: 3,
// groupValue: blindValue,
// onChanged: (value) {
// setState(() => {this.blindValue = value});
//
// setTheme(value);
// },
// ),
// ],
// ),
// ],
// )
// ])),
Container(
padding: EdgeInsets.all(10),
child: AppText(
TranslationBase.of(context).permissions,
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).cameraPermission),
Switch(
value: camera,
onChanged: (value) {
setState(() {
camera = value;
});
permission.setCameraLocationPermission(context);
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
)
],
)),
Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AppText(TranslationBase.of(context).locationPermission),
Switch(
value: location,
onChanged: (value) {
setState(() {
location = value;
});
permission.setCameraLocationPermission(context);
},
activeTrackColor: Colors.lightGreenAccent,
activeColor: Colors.green,
)
],
))
]));
}
setTheme(value) async{
switch (value) {
case 0:
{
themeNotifier.setTheme(await getTheme(value));
Screen.setBrightness(1.0);
}
break;
case 1:
{
themeNotifier.setTheme(await getTheme(value));
Screen.setBrightness(1.0);
}
break;
case 2:
themeNotifier.setTheme(await getTheme(value));
Screen.setBrightness(0.01);
break;
case 3:
{
themeNotifier.setTheme(await getTheme(value));
Screen.setBrightness(1.0);
}
break;
default:
{
themeNotifier.setTheme(await getTheme(value));
Screen.setBrightness(1.0);
}
break;
}
permission.setTheme(value);
}
setVibration(value){
permission.setVibrationPermission(value);
}
getValues() async{
blindValue= permission.isThemeEnabled() == null ? 0 : permission.isThemeEnabled();
vibration = permission.isVibrationEnabled() ==null ? false : permission.isVibrationEnabled();
camera = await permission.isCameraEnabled();
location = await permission.isLocationEnabled();
setState(() {
location =location;
camera = camera;
vibration = vibration;
blindValue =blindValue;
accsibility = mediaQueryData.accessibleNavigation;
});
}
getTheme(value) async{
if(value ==1){
return ThemeData(
fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'en' ? 'WorkSans' : 'Cairo',
primarySwatch: Colors.grey,
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.light,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
hintColor: Colors.grey[400],
cardColor: Colors.black,
buttonColor: Colors.grey[400],
disabledColor: Colors.grey[300],
errorColor: Color.fromRGBO(235, 80, 60, 1.0),
scaffoldBackgroundColor: Colors.grey,
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
textSelectionHandleColor: Colors.grey,
canvasColor: Colors.white,
backgroundColor: Colors.grey,
highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent,
primaryColor: Colors.grey,
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
iconTheme: IconThemeData(),
appBarTheme: AppBarTheme(
color: Colors.grey,
brightness: Brightness.dark,
elevation: 10.0,
actionsIconTheme: IconThemeData(
color: Colors.grey,
),
),
);
}else if(value ==3){
return ThemeData(
fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'en' ? 'WorkSans' : 'Cairo',
primarySwatch: Colors.grey,
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.light,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
hintColor: Colors.grey[400],
cardColor: Colors.black,
buttonColor: Colors.grey[400],
disabledColor: Colors.grey[300],
errorColor: Color.fromRGBO(235, 80, 60, 1.0),
scaffoldBackgroundColor: Colors.grey,
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
textSelectionHandleColor: Colors.grey,
canvasColor: Colors.white,
backgroundColor: Colors.grey,
highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent,
primaryColor: Colors.grey,
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
iconTheme: IconThemeData(),
appBarTheme: AppBarTheme(
color: Colors.black45,
brightness: Brightness.dark,
elevation: 10.0,
actionsIconTheme: IconThemeData(
color: Colors.grey,
),
),
);
}else {
return ThemeData(
fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'en' ? 'WorkSans' : 'Cairo',
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
brightness: Brightness.light,
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.android: ZoomPageTransitionsBuilder(),
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
},
),
hintColor: Colors.grey[400],
disabledColor: Colors.grey[300],
errorColor: Color.fromRGBO(235, 80, 60, 1.0),
scaffoldBackgroundColor: Color(0xffEEEEEE),
textSelectionColor: Color.fromRGBO(80, 100, 253, 0.5),
textSelectionHandleColor: Colors.grey,
canvasColor: Colors.white,
backgroundColor: Colors.white,
highlightColor: Colors.grey[100].withOpacity(0.4),
splashColor: Colors.transparent,
primaryColor: Color(0xff40ACC9),
bottomSheetTheme: BottomSheetThemeData(backgroundColor: Color(0xffE0E0E0)),
cursorColor: Colors.grey,
cardColor: Colors.white,
iconTheme: IconThemeData(),
appBarTheme: AppBarTheme(
color: Color(0xff40ACC9),
brightness: Brightness.dark,
elevation: 10.0,
actionsIconTheme: IconThemeData(
color: Color(0xff40ACC9),
),
),
);
}
}
}