Hello fellow devs,
I'm quite new in FlutterFlow and in dart, flutter also, and now I'm facing a challenge what I don't know how to resolve.
I have a text widget what I populate from my firestore db. Sometimes I have longer words then the dedicated space for the text and it break it incorrectly.
For better help to imagine:
appl
e
I found a package on pub.dev: https://pub.dev/packages/hyphenatorx/example
and I tried to create a custom HyphenatedText widget:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
import 'package:hyphenatorx/hyphenatorx.dart';
import 'package:hyphenatorx/languages/languageconfig.dart';
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
// Set your widget name, define your parameter, and then add the
// boilerplate code using the green button on the right!
class HyphenatedText extends StatefulWidget {
final String text;
final TextStyle? style;
final TextAlign? textAlign;
final TextOverflow? overflow;
final int? maxLines;
const HyphenatedText({
Key? key,
required this.text,
this.style,
this.textAlign,
this.overflow,
this.maxLines,
}) : super(key: key);
@override
_HyphenatedTextState createState() => _HyphenatedTextState();
}
class _HyphenatedTextState extends State<HyphenatedText> {
late Future<String> _hyphenatedText;
@override
void initState() {
super.initState();
_hyphenatedText = _hyphenateText(widget.text);
}
Future<String> _hyphenateText(String text) async {
// Load the Hungarian language patterns
final hyphenator = await Hyphenator.loadAsync(Language.language_hu);
// Hyphenate the text
return hyphenator.hyphenateText(text);
}
@override
Widget build(BuildContext context) {
return FutureBuilder<String>(
future: _hyphenatedText,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Text(
widget.text,
style: widget.style,
textAlign: widget.textAlign,
overflow: widget.overflow,
maxLines: widget.maxLines,
);
} else if (snapshot.hasError) {
return Text(
'Error: ${snapshot.error}',
style: widget.style,
textAlign: widget.textAlign,
overflow: widget.overflow,
maxLines: widget.maxLines,
);
} else {
return Text(
snapshot.data!,
style: widget.style,
textAlign: widget.textAlign,
overflow: widget.overflow,
maxLines: widget.maxLines,
);
}
},
);
}
}
Any time when I try to compile check in FlutterFlow I got an error but the error popup is empty.