import 'package:diplomaticquarterapp/config/shared_pref_kay.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 with TickerProviderStateMixin { var themeNotifier; int blindValue = 0; bool vibration =false; bool accessibility =false; bool camera =false; bool location =false; var sharedPref = new AppSharedPreferences(); @override void initState() { getValues(); super.initState(); } Widget build(BuildContext context) { themeNotifier = Provider.of(context); return Container( child: ListView(scrollDirection: Axis.vertical, children: [ 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: accessibility, onChanged: (value) { setState(() { accessibility = value; }); }, 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: [ new Column( mainAxisAlignment: MainAxisAlignment.center, children: [ 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; }); }, 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; }); }, 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; } sharedPref.setInt(THEME_VALUE, value); } setVibration(value){ sharedPref.setBool(IS_VIBRATION, value); } getValues() async{ blindValue= await sharedPref.getInt(THEME_VALUE) ?? 0; vibration= await sharedPref.getBool(IS_VIBRATION) ?? false; } getTheme(value) async{ if(value ==1){ return ThemeData( fontFamily: await sharedPref.getString(APP_LANGUAGE) == 'ar' ? 'Cairo' : 'WorkSans', 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) == 'ar' ? 'Cairo' : 'WorkSans', 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) == 'ar' ? 'Cairo' : 'WorkSans', 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), ), ), ); } } }