my code:
import 'dart:math';
import 'package:animated_theme_switcher/animated_theme_switcher.dart';
import 'package:appservice/flavors.dart';
import 'package:appservice/helper/dbhelper.dart';
import 'package:appservice/models/localappconfig.dart';
import 'package:appservice/pages/home_page.dart';
import 'package:appservice/services/createtable_services.dart';
import 'package:appservice/widgets/common_snackbar.dart';
import 'package:appservice/widgets/settings/settings_ui_data.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
import 'package:line_awesome_flutter/line_awesome_flutter.dart';
import 'package:progress_dialog/progress_dialog.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../helper/helper.dart';
import '../sqliteProvider/userappconfig_provider.dart';
import '../style/style.dart';
import '../utils/uidata.dart';
class SettingPage extends StatefulWidget {
final String accountName;
final bool reception;
const SettingPage({Key key, this.accountName, this.reception})
: super(key: key);
@override
_SettingPageState createState() => _SettingPageState();
}
class _SettingPageState extends State {
ProgressDialog prDialog;
Color _shadeColor = Colors.orange[400];
Color _tempShadeColor;
ColorSwatch _tempMainColor;
ColorSwatch _mainColor = Colors.deepOrange;
@override
void initState() {
super.initState();
initData();
}
@override
Widget build(BuildContext context) {
// ScreenUtil.init(context, height: 896, width: 414, allowFontScaling: false);
return ThemeSwitchingArea(
child: Builder(
builder: (context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
centerTitle: true,
title: Text(
F.companyInfo.appCompanyName,
),
),
body: Column(
children: [
SizedBox(height: 30.h),
header(),
Expanded(
child: ListView(
children: [
widget.reception
? _widgetGetDataFromSazmani(context)
: SizedBox(),
_widgetThemeColor(context),
_widgetFontSize(),
_widgetLogout(context),
colorChange(),
],
),
)
],
),
);
},
),
);
}
Future initData() async {
prDialog = new ProgressDialog(context,
type: ProgressDialogType.Normal, isDismissible: false);
prDialog.style(
message: 'چند لحظه صبر نمایید ',
borderRadius: 10.0,
backgroundColor: Colors.white,
elevation: 10.0,
insetAnimCurve: Curves.easeInOut,
progressTextStyle: Style.styleTextBlack(TEXT_SIZE_22, FontWeight.w400),
messageTextStyle: Style.styleTextBlack(TEXT_SIZE_30, FontWeight.w400),
);
}
Widget header() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(width: 40.w),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Directionality(
textDirection: TextDirection.rtl, child: HomePage())),
);
},
child: Icon(
LineAwesomeIcons.arrow_right,
size: ScreenUtil().setSp(50),
),
),
profileInfo(),
themeSwitcher(),
SizedBox(width: 40.w),
],
);
}
Widget profileInfo() {
return Expanded(
child: Column(
children: [
Container(
height: 150.h,
width: 165.w,
margin: EdgeInsets.only(top: 55.h),
child: Stack(
children: [
CircleAvatar(
radius: 80,
backgroundImage: AssetImage('assets/images/admin.png'),
),
],
),
),
SizedBox(height: 40.h),
Text(widget.accountName,
style: Style.styleTextBlack(TEXT_SIZE_24, FontWeight.w700)),
SizedBox(height: 60.h),
Container(
height: 70.h,
width: 300.w,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Theme.of(context).accentColor,
),
child: widgetDownloadApk(),
),
SizedBox(height: 35.h),
],
),
);
}
Widget _widgetGetDataFromSazmani(BuildContext context) {
return InkWell(
onTap: () {
_getdata(context);
},
child: _widgetContent("دریافت اطلاعات پذیرش", LineAwesomeIcons.upload),
);
}
Future _getdata(BuildContext context) async {
await Helper.isOnline().then((isOnline) async {
if (isOnline) {
prDialog.show();
bool result = false;
double _netserverversion = 0;
_netserverversion = await TableService.getVersion();
DbHelper dbHelper = new DbHelper();
var map = await dbHelper.getItem('LocalAppConfig');
LocalAppConfig appConfig = new LocalAppConfig.fromMap(map);
if (appConfig != null && appConfig.version == 0) {
result = await Helper.getDataSazmaniUntilEnd(_netserverversion);
} else if (appConfig != null &&
appConfig.version != netserverversion) {
await TableService.getAlterTable().then(() async {
result = await Helper.getDataSazmaniUntilEnd(_netserverversion);
});
} else {
result = await Helper.getDataSazmaniUntilEnd(_netserverversion);
}
if (!result) if (prDialog.isShowing()) prDialog.hide();
} else
FlushbarHelper.createInformation(
context: context,
message: "عدم ارتباط با سرور ،مجددا اقدام نمایید.",
title: "توجه");
});
}
Widget widgetDownloadApk() {
return InkWell(
onTap: _launchURL,
child: Row(
children: [
SizedBox(width: 45.w),
Text(
"بروز رسانی ",
style: Style.styleTextBlack(TEXT_SIZE_24, FontWeight.w700),
),
SizedBox(width: 80.w),
Icon(
Icons.update_outlined,
size: 40.w,
),
],
),
);
}
_launchURL() async {
String url = F.companyInfo.urlDownload +
'WebApiB2BDotCore/UploadedFiles/Apk/b2bsorooshan.apk?${Random().nextInt(10000)}';
if (await canLaunch(url)) {
await launch(url);
}
}
Widget _widgetLogout(BuildContext context) {
return Container(
child: InkWell(
onTap: () {
Helper.onConfirmEasyDialog(
context,
'خروج',
'آیا از خروج از حساب کاربری اطمینان دارید؟',
_logout,
_cancel(context));
},
child: _widgetContent(
"خروج از حساب کاربری", LineAwesomeIcons.alternate_sign_out),
),
);
}
_logout() {
UserAppConfigProvider configProvider = UserAppConfigProvider();
configProvider.logOutUser(1, true).then((value) {
Helper.onExit();
});
}
_cancel(BuildContext context) => Navigator.of(context).pop(true);
Widget _widgetThemeColor(BuildContext context) {
return InkWell(
onTap: _openColorPicker,
child: _widgetContent(
" تغییر رنگ برنامه ", LineAwesomeIcons.paint_roller));
}
Widget _widgetFontSize() {
return InkWell(
onTap: () {},
child: _widgetContent(
" تغییر سایز فونت ", LineAwesomeIcons.alternate_pencil),
);
}
Widget _widgetContent(String title, IconData icon) {
return Container(
height: 90.h,
margin: EdgeInsets.symmetric(
horizontal: 60.w,
).copyWith(
bottom: 40.h,
),
padding: EdgeInsets.symmetric(
horizontal: 50.w,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Theme.of(context).backgroundColor,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(title,
style: Style.styleTextBlack(TEXT_SIZE_24, FontWeight.w700)),
Icon(
icon,
size: 30,
),
// Spacer(),
],
),
);
}
Widget themeSwitcher() {
return ThemeSwitcher(
builder: (context) {
return AnimatedCrossFade(
duration: Duration(milliseconds: 200),
crossFadeState:
ThemeProvider.of(context).brightness == Brightness.dark
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: GestureDetector(
onTap: () =>
ThemeSwitcher.of(context).changeTheme(theme: kLightTheme),
child: Icon(
LineAwesomeIcons.sun,
size: ScreenUtil().setSp(50),
),
),
secondChild: GestureDetector(
onTap: () =>
ThemeSwitcher.of(context).changeTheme(theme: kDarkTheme),
child: Icon(
LineAwesomeIcons.moon,
size: ScreenUtil().setSp(50),
),
),
);
},
);
}
ThemeData selectedColorTheme(BuildContext context) => ThemeData(
accentColor: _shadeColor,
appBarTheme: ThemeData.dark().appBarTheme.copyWith(color: _shadeColor),
);
void _openColorPicker() async {
_openDialog(
"Color picker",
MaterialColorPicker(
selectedColor: _shadeColor,
onColorChange: (color) {
_tempShadeColor = Color(color.value);
},
onMainColorChange: (color) {
_tempMainColor = color;
},
),
);
}
void openDialog(String title, Widget content) {
showDialog(
context: context,
builder: () {
return AlertDialog(
contentPadding: const EdgeInsets.all(6.0),
title: Text(title),
content: content,
actions: [
FlatButton(
child: Text('CANCEL'),
onPressed: Navigator.of(context).pop,
),
GestureDetector(
child: Text('SUBMIT'),
onTap: () {
Navigator.of(context).pop();
_mainColor = _tempMainColor;
_shadeColor = _tempShadeColor;
},
),
],
);
},
);
}
Widget colorChange() {
return ThemeSwitcher(
builder: (context) {
return Container(
child: RaisedButton(
child: Text(" change color "),
onPressed: () {
ThemeSwitcher.of(context).changeTheme(
theme: selectedColorTheme(context),
);
},
),
);
},
);
}
}
when i click the " change color " Button , this error " The getter 'dx' was called on null. Receiver: null Tried calling: dx " occur in debug consol
Can you help me ?????