Add multi string - translation logic (save)
This commit is contained in:
parent
6b0f3145c1
commit
9a5e9b74a0
@ -1,17 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:manager_app/Components/rounded_button.dart';
|
||||
import 'package:manager_app/Components/string_input_container.dart';
|
||||
import 'package:manager_app/Components/translation_tab.dart';
|
||||
import 'package:manager_app/constants.dart';
|
||||
import 'package:managerapi/api.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
showMultiStringInput (List<TranslationDTO> values, ValueChanged<List<TranslationDTO>> onChanged, BuildContext context) { /*Function onSelect,*/
|
||||
List<TranslationDTO> newValues = new List<TranslationDTO>();
|
||||
newValues = values;
|
||||
showMultiStringInput (String text, List<TranslationDTO> values, List<TranslationDTO> newValues, Function onGetResult, int maxLines, BuildContext context) { /*Function onSelect,*/
|
||||
showDialog(
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: Text(text),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 500,
|
||||
height: 200,
|
||||
child: TranslationTab(
|
||||
translations: newValues,
|
||||
maxLines: maxLines
|
||||
)
|
||||
),
|
||||
/*Column(
|
||||
children: showValues(newValues),
|
||||
),*/
|
||||
],
|
||||
)
|
||||
),
|
||||
actions: <Widget>[
|
||||
@ -26,7 +39,7 @@ showMultiStringInput (List<TranslationDTO> values, ValueChanged<List<Translation
|
||||
icon: Icons.undo,
|
||||
color: kSecond,
|
||||
press: () {
|
||||
onChanged(values);
|
||||
onGetResult(values);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
fontSize: 20,
|
||||
@ -41,7 +54,10 @@ showMultiStringInput (List<TranslationDTO> values, ValueChanged<List<Translation
|
||||
color: kPrimaryColor,
|
||||
textColor: kWhite,
|
||||
press: () {
|
||||
onChanged(newValues);
|
||||
Function deepEq = const DeepCollectionEquality().equals;
|
||||
if (!deepEq(values, newValues)) {
|
||||
onGetResult(newValues);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
fontSize: 20,
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:manager_app/Components/multi_input_modal.dart';
|
||||
@ -9,13 +11,15 @@ class MultiStringContainer extends StatelessWidget {
|
||||
final Color color;
|
||||
final String label;
|
||||
final List<TranslationDTO> initialValue;
|
||||
final ValueChanged<List<TranslationDTO>> onChanged;
|
||||
final Function onGetResult;
|
||||
final int maxLines;
|
||||
const MultiStringContainer({
|
||||
Key key,
|
||||
this.color = kSecond,
|
||||
this.label,
|
||||
this.initialValue,
|
||||
this.onChanged,
|
||||
this.onGetResult,
|
||||
this.maxLines,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -34,7 +38,12 @@ class MultiStringContainer extends StatelessWidget {
|
||||
width: size.width *0.15,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
showMultiStringInput(initialValue, onChanged, context);
|
||||
List<TranslationDTO> newValues = new List<TranslationDTO>();
|
||||
// Make a copy
|
||||
initialValue.forEach((value) {
|
||||
newValues.add(TranslationDTO.fromJson(jsonDecode(jsonEncode(value))));
|
||||
});
|
||||
showMultiStringInput(label, initialValue, newValues, onGetResult, maxLines, context);
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
|
||||
@ -0,0 +1,110 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:manager_app/constants.dart';
|
||||
import 'package:managerapi/api.dart';
|
||||
class TranslationTab extends StatefulWidget {
|
||||
final List<TranslationDTO> translations;
|
||||
final int maxLines;
|
||||
const TranslationTab({
|
||||
Key key,
|
||||
this.translations,
|
||||
this.maxLines,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_TranslationTabState createState() => _TranslationTabState();
|
||||
}
|
||||
|
||||
class _TranslationTabState extends State<TranslationTab> with SingleTickerProviderStateMixin {
|
||||
TabController _tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_tabController = new TabController(length: widget.translations.length, vsync: this);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
TabBar(
|
||||
unselectedLabelColor: Colors.black,
|
||||
labelColor: kPrimaryColor,
|
||||
tabs: getTabs(widget.translations),
|
||||
controller: _tabController,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
indicatorColor: kPrimaryColor,
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
children: getContent(widget.translations, widget.maxLines),
|
||||
controller: _tabController,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
getContent(List<TranslationDTO> translations, int maxLines) {
|
||||
List<Widget> tabsToShow = new List<Widget>();
|
||||
translations.forEach((translation) {
|
||||
tabsToShow.add(
|
||||
new Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
|
||||
child: TextFormField (
|
||||
keyboardType: TextInputType.multiline,
|
||||
textInputAction: TextInputAction.newline,
|
||||
minLines: 1,
|
||||
maxLines: maxLines,
|
||||
initialValue: translation.value,
|
||||
onChanged: (String value) {
|
||||
translation.value = value;
|
||||
},
|
||||
cursorColor: kPrimaryColor,
|
||||
decoration: InputDecoration(
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: kPrimaryColor),
|
||||
),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: kPrimaryColor),
|
||||
),
|
||||
border: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: kPrimaryColor),
|
||||
),
|
||||
)
|
||||
|
||||
)
|
||||
),
|
||||
/*new Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Container(
|
||||
width: 200,
|
||||
child: RoundedInputField(
|
||||
color: kSecond,
|
||||
textColor: kBlack,
|
||||
initialValue: translation.value,
|
||||
onChanged: (String value) {
|
||||
translation.value = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
)*/
|
||||
);
|
||||
});
|
||||
return tabsToShow;
|
||||
}
|
||||
|
||||
getTabs(List<TranslationDTO> newValues) {
|
||||
List<Tab> tabsToShow = new List<Tab>();
|
||||
newValues.forEach((value) {
|
||||
tabsToShow.add(
|
||||
new Tab(text: value.language));
|
||||
});
|
||||
return tabsToShow;
|
||||
}
|
||||
@ -155,16 +155,24 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
||||
MultiStringContainer(
|
||||
label: "Titre :",
|
||||
initialValue: sectionDTO.title,
|
||||
onChanged: (value) {
|
||||
onGetResult: (value) {
|
||||
if (sectionDTO.title != value) {
|
||||
sectionDTO.title = value;
|
||||
save(true, sectionDTO, appContext);
|
||||
}
|
||||
},
|
||||
maxLines: 1,
|
||||
),
|
||||
MultiStringContainer(
|
||||
label: "Description :",
|
||||
initialValue: sectionDTO.description,
|
||||
onChanged: (value) {
|
||||
onGetResult: (value) {
|
||||
if (sectionDTO.description != value) {
|
||||
sectionDTO.description = value;
|
||||
save(true, sectionDTO, appContext);
|
||||
}
|
||||
},
|
||||
maxLines: 2,
|
||||
)
|
||||
],
|
||||
)
|
||||
@ -223,7 +231,7 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
||||
textColor: Colors.white,
|
||||
fontSize: 15,
|
||||
press: () {
|
||||
save(sectionDTO, appContext);
|
||||
save(false, sectionDTO, appContext);
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -253,14 +261,20 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> save(SectionDTO sectionDTO, AppContext appContext) async {
|
||||
Future<void> save(bool isTraduction, SectionDTO sectionDTO, AppContext appContext) async {
|
||||
print("SAVE");
|
||||
print(sectionDTO);
|
||||
SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionUpdate(sectionDTO);
|
||||
ManagerAppContext managerAppContext = appContext.getContext();
|
||||
managerAppContext.selectedSection = section;
|
||||
appContext.setContext(managerAppContext);
|
||||
|
||||
if (isTraduction) {
|
||||
showNotification(Colors.green, kWhite, 'Les traductions de la section ont été sauvegardées avec succès', context);
|
||||
} else {
|
||||
showNotification(Colors.green, kWhite, 'La section a été sauvegardée avec succès', context);
|
||||
}
|
||||
}
|
||||
|
||||
getSpecificData(SectionDTO sectionDTO, AppContext appContext) {
|
||||
switch(sectionDTO.type) {
|
||||
|
||||
@ -44,12 +44,19 @@ packages:
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.15.0"
|
||||
convert:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: convert
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@ -30,6 +30,8 @@ dependencies:
|
||||
flutter_colorpicker: ^0.4.0
|
||||
multiselect_formfield: ^0.1.6
|
||||
material_segmented_control: ^3.1.2
|
||||
convert: ^3.0.0
|
||||
collection: any
|
||||
managerapi:
|
||||
path: manager_api
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user