Hello, I have a problem, when I write in the text editor and scroll so that the editor is hidden, when scrolling back to the editor all content has been redesigned and the text disappears. How to solve this?
class AdminAddProjectPageMobile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final supportStore = Provider.of<SupportStore>(context);
final teacherFirestore = Provider.of<TeacherFirestore>(context);
final _picker = ImagePicker();
final HtmlEditorController contentController = HtmlEditorController();
final projectFirestore = Provider.of<ProjectFirestore>(context);
final TextEditingController controllerParticipants =
TextEditingController();
final teacherStore = Provider.of<TeacherStore>(context);
return Observer(
builder: (ctx) {
teacherStore.listTeachers?? teacherStore.getTeachers();
print("xxx");
switch(teacherStore.listTeachers!.status){
case FutureStatus.pending:
return CustomLoading();
case FutureStatus.fulfilled:
List<Teacher> listTeachers = teacherStore.listTeachers!.value as List<Teacher>;
supportStore.createTeacherLocal(listTeachers, null);
return SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomTextFormField(
hintText: "Insira o titulo",
labelText: "Titulo",
maxCharacters: 30,
initialValue: supportStore.titleProject,
onChanged: (text) {
supportStore.updateTitle(text);
},
textInputType: TextInputType.name,
),
Observer(builder: (_) {
return supportStore.msgErrorTitle == ""
? Container()
: ErrorMsg(supportStore.msgErrorTitle);
}),
Padding(
padding: const EdgeInsets.all(8.0),
child: CustomText("Imagem titulo",
style: Theme.of(context).textTheme.headline6)),
Observer(
builder: (ctx) => Container(
decoration: supportStore.pathImage!.path != ""
? BoxDecoration(
image: DecorationImage(
image: NetworkImage(supportStore.pathImage!.path),
fit: BoxFit.fill,
))
: BoxDecoration(color: Colors.grey),
child: Row(children: [
supportStore.pathImage!.path != ""
? Expanded(
flex: 95,
child: Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: AutoSizeText(
supportStore.titleProject,
minFontSize: 10,
style: Theme.of(context)
.textTheme
.headline3!
.copyWith(fontSize: 30),
),
),
),
)
: Expanded(flex:85,child: Container()),
Spacer(),
Expanded(
flex: 5,
child: InkWell(
child: Icon(Icons.folder),
onTap: () async {
PickedFile? image = await _picker.getImage(
source: ImageSource.camera);
supportStore.updatePath(image);
}),
),
]),
height: supportStore.pathImage!.path == "" ? 40 : 300,
),
),
Observer(builder: (_) {
return supportStore.msgErrorImage == ""
? Container()
: ErrorMsg(supportStore.msgErrorImage);
}),
CustomHtmlEditor(
padding: EdgeInsets.symmetric(vertical: 16.0),
controller: contentController,
onChange: supportStore.updateContent,
initialText: supportStore.htmlContent,
),
Observer(builder: (_) {
return supportStore.msgErrorContent == ""
? Container()
: ErrorMsg(supportStore.msgErrorContent);
}),
Center(
child: CustomText(
"Selecione os professores que participam do projeto",
style: Theme.of(context).textTheme.subtitle1),
),
Observer(builder: (_) {
return supportStore.msgErrorTeacher == ""
? Container()
: ErrorMsg(supportStore.msgErrorTeacher);
}),
Observer(
builder: (context) => ListView.builder(
itemCount: supportStore.teacherLocal.length,
shrinkWrap: true,
itemBuilder: (ctx, index) {
return CustomCheckBox(
title: supportStore.teacherLocal[index].name,
value: supportStore.teacherLocal[index].checked,
onChanged: (_) {
supportStore.updateTeacherLocal(
supportStore.teacherLocal[index], index);
});
})),
SizedBox(
height: 40,
),
Center(
child: CustomText("Escreva os alunos que participam do projeto",
style: Theme.of(context).textTheme.subtitle1),
),
Observer(builder: (_) {
return supportStore.msgErrorParticipants == ""
? Container()
: ErrorMsg(supportStore.msgErrorParticipants);
}),
CustomTextFormField(
controller: controllerParticipants,
textInputType: TextInputType.number,
hintText: "Digite o numero de participantes (Max. 10)",
labelText: "Numero de participantes",
),
CustomButton(
paddingButton: EdgeInsets.all(8.0),
expandButton: true,
text: "Gerar participantes",
onPressed: () {
supportStore.validateParticipant(controllerParticipants.text);
FocusScope.of(context).unfocus();
}),
Observer(builder: (_) {
return supportStore.msgErrorParticipantsSize == ""
? Container()
: ErrorMsg(supportStore.msgErrorParticipantsSize);
}),
Observer(
builder: (context) => ListView.builder(
shrinkWrap: true,
itemCount: supportStore.participantsLocal.length,
itemBuilder: (ctx, index) {
return CustomTextFormField(
textInputType: TextInputType.name,
onChanged: (value) =>
supportStore.updateParticipants(value, index),
hintText: "Nome Participante ${index + 1}",
labelText: 'Participante ${index + 1}',
);
},
),
),
CustomButton(
text: "Criar Projeto",
onPressed: () async {
if (supportStore.validate()) {
var result = await projectFirestore.addProject(
supportStore.titleProject,
supportStore.pathImage,
supportStore.htmlContent,
supportStore.getTeachers(),
supportStore.getParticipantsLocalFilled(),
projectFirestore.username);
supportStore.clearData();
VxNavigator.of(context)
.push(Uri.parse(RouteNames.ADMIN_PROJECTS));
if (result) {
CustomToast.showToast(
"Projeto cadastro com sucesso!!", Colors.green);
} else {
CustomToast.showToast(
"Não foi possivel cadastrar seu projeto, tente novamente mais tarde.",
Colors.red,
);
}
}
},
),
],
),
),
);
case FutureStatus.rejected:
return ErrorLoad(
color: Theme.of(context).primaryColor,
);
}
},
);
}
class CustomHtmlEditor extends StatelessWidget{
final dynamic Function(String?)? onChange;
final String? initialText;
final HtmlEditorController controller;
final dynamic Function()? onInit;
final EdgeInsets padding;
final height;
CustomHtmlEditor(
{required this.onChange, this.initialText, required this.controller,this.onInit,this.padding=EdgeInsets.zero,this.height=400});
@override
Widget build(BuildContext context) {
return Container(
height: height,
child: Theme(
data: ThemeData(
primaryColor: Colors.red,
selectedRowColor: Colors.red,
textTheme: Theme.of(context).textTheme.apply(
bodyColor: Theme.of(context).primaryColor,
displayColor: Theme.of(context).primaryColor,
decorationColor: Theme.of(context).primaryColor,
)),
child: HtmlEditor(
controller: controller,
htmlEditorOptions: HtmlEditorOptions(
hint: "Escreva o texto aqui...",
initialText: initialText,
),
otherOptions: OtherOptions(
height: height,
),
callbacks: Callbacks(
onChange: onChange,
onFocus: ()=>print("focused"),onBlur: () {
FocusScope.of(context).unfocus();
},
),
htmlToolbarOptions: HtmlToolbarOptions(
mediaLinkInsertInterceptor:
(String url, InsertFileType type) {
print(url);
return true;
},
buttonFocusColor: Theme.of(context).primaryColor,
buttonColor: Theme.of(context).primaryColor,
buttonBorderColor: Colors.black,
buttonFillColor: Theme.of(context).backgroundColor,
buttonSelectedColor: Theme.of(context).primaryColor,
dropdownFocusColor: Theme.of(context).primaryColor,
textStyle: Theme.of(context)
.textTheme
.caption!
.copyWith(color: Theme.of(context).primaryColor),
toolbarType: ToolbarType.nativeGrid,
defaultToolbarButtons: [
StyleButtons(),
FontSettingButtons(fontSizeUnit: false),
FontButtons(
clearAll: false, superscript: false, subscript: false),
ParagraphButtons(
increaseIndent: false,
decreaseIndent: false,
textDirection: false,
lineHeight: false,
caseConverter: false),
InsertButtons(
otherFile: false,
),
]),
),
),
);