129 lines
4.7 KiB
Dart
129 lines
4.7 KiB
Dart
import 'package:aitrainer_app/bloc/menu/menu_bloc.dart';
|
|
import 'package:aitrainer_app/bloc/settings/settings_bloc.dart';
|
|
import 'package:aitrainer_app/library/custom_icon_icons.dart';
|
|
import 'package:aitrainer_app/localization/app_language.dart';
|
|
import 'package:aitrainer_app/model/cache.dart';
|
|
import 'package:aitrainer_app/util/trans.dart';
|
|
import 'package:aitrainer_app/widgets/app_bar_min.dart';
|
|
import 'package:aitrainer_app/widgets/bottom_nav.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:toggle_switch/toggle_switch.dart';
|
|
|
|
// ignore: must_be_immutable
|
|
class SettingsPage extends StatelessWidget with Trans {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// ignore: close_sinks
|
|
SettingsBloc settingsBloc = BlocProvider.of<SettingsBloc>(context);
|
|
settingsBloc.setLocale(AppLanguage().appLocal);
|
|
settingsBloc.context = context;
|
|
setContext(context);
|
|
|
|
MenuBloc menuBloc = BlocProvider.of<MenuBloc>(context);
|
|
return Scaffold(
|
|
appBar: AppBarMin(),
|
|
body: Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_light_background.png'),
|
|
fit: BoxFit.cover,
|
|
alignment: Alignment.center,
|
|
),
|
|
),
|
|
child: Form(
|
|
child: BlocConsumer<SettingsBloc, SettingsState>(listener: (context, state) {
|
|
if (state is SettingsError) {
|
|
} else if (state is SettingsReady) {
|
|
menuBloc.add(MenuRecreateTree());
|
|
} else if (state is SettingsLoading) {
|
|
Scaffold.of(context).showSnackBar(SnackBar(
|
|
duration: Duration(milliseconds: 100),
|
|
backgroundColor: Colors.transparent,
|
|
content: Container(child: Center(child: CircularProgressIndicator()))));
|
|
}
|
|
},
|
|
// ignore: missing_return
|
|
builder: (context, state) {
|
|
return settingsUI(context, settingsBloc, menuBloc);
|
|
}),
|
|
),
|
|
),
|
|
bottomNavigationBar: BottomNavigator(bottomNavIndex: 4));
|
|
}
|
|
|
|
ListView settingsUI(BuildContext context, SettingsBloc settingsBloc, MenuBloc menuBloc) {
|
|
return ListView(padding: EdgeInsets.only(top: 150), children: <Widget>[
|
|
ListTile(
|
|
leading: Icon(Icons.language),
|
|
subtitle: Text(t("Change App Language")),
|
|
title: DropdownButton(
|
|
value: settingsBloc.getLocale() == Locale('en') ? t("English") : t("Hungarian"),
|
|
items: [t("English"), t("Hungarian")].map<DropdownMenuItem<String>>((String value) {
|
|
return DropdownMenuItem<String>(
|
|
value: value,
|
|
child: Text(value),
|
|
);
|
|
}).toList(),
|
|
onChanged: (String lang) => {
|
|
settingsBloc.add(SettingsChangeLanguage(language: lang)),
|
|
})),
|
|
getServer(settingsBloc),
|
|
getDevice(settingsBloc),
|
|
]);
|
|
}
|
|
|
|
ListTile getServer(SettingsBloc settingsBloc) {
|
|
if (Cache().userLoggedIn.admin != 1) {
|
|
return ListTile(
|
|
title: Container(),
|
|
);
|
|
}
|
|
return ListTile(
|
|
leading: Icon(Icons.data_usage_sharp),
|
|
subtitle: Text("For Test purpuses select Test-Server. After that please restart the the App"),
|
|
title: ToggleSwitch(
|
|
minWidth: 120.0,
|
|
minHeight: 30.0,
|
|
fontSize: 14.0,
|
|
initialLabelIndex: Cache().liveServer
|
|
? Cache().testEnvironment == "1"
|
|
? 1
|
|
: 0
|
|
: 1,
|
|
activeBgColor: Colors.indigo,
|
|
activeFgColor: Colors.white,
|
|
inactiveBgColor: Colors.white60,
|
|
inactiveFgColor: Colors.grey[900],
|
|
labels: [t('Live-Server'), t('Test-Server')],
|
|
onToggle: (index) {
|
|
//Cache().setServer(index == 0);
|
|
settingsBloc.add(SettingsSetServer(live: index == 0));
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
ListTile getDevice(SettingsBloc settingsBloc) {
|
|
return ListTile(
|
|
leading: Icon(CustomIcon.cog),
|
|
subtitle: Text("Do you have Smart watch, or any device which collects the fit/health data?"),
|
|
title: ToggleSwitch(
|
|
minWidth: 120.0,
|
|
minHeight: 30.0,
|
|
fontSize: 14.0,
|
|
initialLabelIndex: Cache().hasHardware ? 0 : 1,
|
|
activeBgColor: Colors.indigo,
|
|
activeFgColor: Colors.white,
|
|
inactiveBgColor: Colors.white60,
|
|
inactiveFgColor: Colors.grey[900],
|
|
labels: [t('Yes'), t('No')],
|
|
onToggle: (index) {
|
|
settingsBloc.add(SettingsSetHardware(hasHardware: index == 0));
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|