352 lines
11 KiB
Dart
352 lines
11 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:mobdr/config/constant.dart';
|
|
import 'package:mobdr/config/global_style.dart';
|
|
import 'package:mobdr/main.dart';
|
|
import 'package:mobdr/cubit/language/app_localizations.dart';
|
|
import 'package:mobdr/ui/reusable/reusable_widget.dart';
|
|
import 'package:mobdr/service/shared_prefs.dart';
|
|
import 'package:mobdr/service/plausible.dart';
|
|
import 'package:mobdr/service/logger_util.dart';
|
|
import 'package:mobdr/events.dart';
|
|
|
|
class SettingsPage extends StatefulWidget {
|
|
@override
|
|
_SettingsPageState createState() => _SettingsPageState();
|
|
}
|
|
|
|
class _SettingsPageState extends State<SettingsPage> {
|
|
// initialize reusable widget
|
|
final _reusableWidget = ReusableWidget();
|
|
|
|
late String _photoQuality;
|
|
late bool _photoResizing;
|
|
late bool _photoSound;
|
|
late String _language;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// track & log page access
|
|
final page = 'settings';
|
|
LoggerUtil.dblog('LOG', 'MOBDR', 'Page : ${page}', 0);
|
|
PlausibleUtil.addEventAsync(name: 'pageview', page: page);
|
|
|
|
setState(() {
|
|
_photoQuality = SharedPrefs().photoQuality;
|
|
_photoResizing = SharedPrefs().photoResizing;
|
|
_photoSound = SharedPrefs().photoSound;
|
|
|
|
switch (SharedPrefs().langage) {
|
|
case 'en':
|
|
_language = 'English';
|
|
break;
|
|
case 'fr':
|
|
_language = 'French';
|
|
break;
|
|
default:
|
|
_language = 'French';
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
iconTheme: IconThemeData(
|
|
color: GlobalStyle.appBarIconThemeColor,
|
|
),
|
|
elevation: GlobalStyle.appBarElevation,
|
|
title: Text(
|
|
AppLocalizations.of(context)!.translate('i18n_menu_settings'),
|
|
style: GlobalStyle.appBarTitle,
|
|
),
|
|
backgroundColor: GlobalStyle.appBarBackgroundColor,
|
|
systemOverlayStyle: GlobalStyle.appBarSystemOverlayStyle,
|
|
bottom: _reusableWidget.bottomAppBar(),
|
|
),
|
|
body: ListView(
|
|
children: [
|
|
_buildSettingsContainer(),
|
|
Divider(height: 0, color: Colors.grey[400]),
|
|
_buildLanguageContainer(),
|
|
Divider(height: 0, color: Colors.grey[400]),
|
|
],
|
|
));
|
|
}
|
|
|
|
Widget _buildSettingsContainer() {
|
|
return Container(
|
|
color: Colors.white,
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.translucent,
|
|
onTap: () {
|
|
showModalBottomSheet<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return _showQualityPopup();
|
|
},
|
|
);
|
|
},
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context)!
|
|
.translate('i18n_label_photo_quality'),
|
|
style: TextStyle(fontSize: 15, color: CHARCOAL)),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
_photoQuality,
|
|
style: TextStyle(
|
|
color: CHARCOAL,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.chevron_right,
|
|
size: 20,
|
|
color: SOFT_GREY,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Divider(height: 0, color: Colors.grey[400]),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 16, right: 4),
|
|
child: SwitchListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: Text(
|
|
AppLocalizations.of(context)!
|
|
.translate('i18n_label_photo_resizing'),
|
|
style: TextStyle(fontSize: 15, color: CHARCOAL),
|
|
),
|
|
value: _photoResizing,
|
|
activeColor: PRIMARY_COLOR,
|
|
onChanged: (bool value) {
|
|
setState(() {
|
|
_photoResizing = value;
|
|
SharedPrefs().photoResizing = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
Divider(height: 0, color: Colors.grey[400]),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 16, right: 4),
|
|
child: SwitchListTile(
|
|
contentPadding: EdgeInsets.zero,
|
|
title: Text(
|
|
AppLocalizations.of(context)!
|
|
.translate('i18n_label_sound_photo'),
|
|
style: TextStyle(fontSize: 15, color: CHARCOAL),
|
|
),
|
|
value: _photoSound,
|
|
activeColor: PRIMARY_COLOR,
|
|
onChanged: (bool value) {
|
|
setState(() {
|
|
_photoSound = value;
|
|
SharedPrefs().photoSound = value;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildLanguageContainer() {
|
|
return GestureDetector(
|
|
behavior: HitTestBehavior.translucent,
|
|
onTap: () {
|
|
showModalBottomSheet<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return _showLanguagePopup();
|
|
},
|
|
);
|
|
},
|
|
child: Container(
|
|
color: Colors.white,
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
AppLocalizations.of(context)!
|
|
.translate('i18n_label_language'),
|
|
style: TextStyle(fontSize: 15, color: CHARCOAL)),
|
|
Row(
|
|
children: [
|
|
Text(
|
|
_language,
|
|
style: TextStyle(
|
|
color: CHARCOAL,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.chevron_right,
|
|
size: 20,
|
|
color: SOFT_GREY,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _showQualityPopup() {
|
|
List<String> qualityOptions = [
|
|
'medium',
|
|
'high',
|
|
'veryHigh',
|
|
'ultraHigh',
|
|
'max'
|
|
];
|
|
|
|
return StatefulBuilder(
|
|
builder: (BuildContext context, StateSetter mystate) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(
|
|
child: Container(
|
|
margin: EdgeInsets.only(top: 12, bottom: 12),
|
|
width: 40,
|
|
height: 4,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[500],
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
|
|
child: Text(
|
|
AppLocalizations.of(context)!
|
|
.translate('i18n_label_choose_quality'),
|
|
style: GlobalStyle.chooseCourier,
|
|
),
|
|
),
|
|
Flexible(
|
|
child: ListView.builder(
|
|
padding: EdgeInsets.all(16),
|
|
itemCount: qualityOptions.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
String qualityOption = qualityOptions[index];
|
|
return RadioListTile<String>(
|
|
dense: true, // Ajouter cette ligne
|
|
title: Text(qualityOption),
|
|
value: qualityOption,
|
|
groupValue: _photoQuality,
|
|
onChanged: (String? value) {
|
|
setState(() {
|
|
_photoQuality = value!;
|
|
SharedPrefs().photoQuality =
|
|
value; // TODO : Passer par un numéro plutot qu'une chaine qui sera traduite ...
|
|
});
|
|
Navigator.pop(context);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _showLanguagePopup() {
|
|
List<String> languageOptions = ['English', 'French'];
|
|
|
|
return StatefulBuilder(
|
|
builder: (BuildContext context, StateSetter mystate) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(
|
|
child: Container(
|
|
margin: EdgeInsets.only(top: 12, bottom: 12),
|
|
width: 40,
|
|
height: 4,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[500],
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
|
|
child: Text(
|
|
AppLocalizations.of(context)!
|
|
.translate('i18n_label_choose_language'),
|
|
style: GlobalStyle.chooseCourier,
|
|
),
|
|
),
|
|
Flexible(
|
|
child: ListView.builder(
|
|
padding: EdgeInsets.all(16),
|
|
itemCount: languageOptions.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
String languageOption = languageOptions[index];
|
|
return RadioListTile<String>(
|
|
title: Text(
|
|
languageOption,
|
|
style: GlobalStyle.courierType,
|
|
),
|
|
value: languageOption,
|
|
groupValue: _language,
|
|
onChanged: (String? value) {
|
|
setState(() {
|
|
_language = value!;
|
|
|
|
switch (value) {
|
|
case 'English':
|
|
SharedPrefs().langage = 'en';
|
|
eventBus.fire(ChangeLocaleEvent('en'));
|
|
break;
|
|
case 'French':
|
|
SharedPrefs().langage = 'fr';
|
|
eventBus.fire(ChangeLocaleEvent('fr'));
|
|
break;
|
|
default:
|
|
_language = 'French';
|
|
break;
|
|
}
|
|
});
|
|
Navigator.pop(context);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|