-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to override tap click on "Read More" & "Read Less". #76
Comments
Can you check if this works for you? class MyWidget extends StatefulWidget {
const MyWidget({super.key});
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
final isCollapsed = ValueNotifier<bool>(true);
@override
void initState() {
super.initState();
isCollapsed.addListener(() {
final currentValue = isCollapsed.value;
if (!currentValue) {
// optionaly close back
isCollapsed.value = false;
// Open bottom sheet
showModalBottomSheet<void>(
context: context,
...
);
}
});
}
@override
void dispose() {
isCollapsed.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ReadMoreText(
'ReadMoreText',
isCollapsed: isCollapsed,
);
}
}
|
I tried this code and function got executed. But for my requirement, I don't want the text to expand. I tried the
|
Do not use This one should work. class MyWidget extends StatefulWidget {
const MyWidget({super.key});
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
final isCollapsed = ValueNotifier<bool>(true);
@override
void initState() {
super.initState();
isCollapsed.addListener(() {
final currentValue = isCollapsed.value;
if (!currentValue) {
isCollapsed.value = true; // Always set to true so Text will never expand
// Open bottom sheet
ScaffoldMessenger.of(context)
..hideCurrentSnackBar()
..showSnackBar(SnackBar(content: Text('Fake dialog opened')));
}
});
}
@override
void dispose() {
isCollapsed.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ReadMoreText(
'ReadMoreText',
isCollapsed: isCollapsed,
);
}
}
|
Will try this and let you know. Thanks for the reply! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a scenario in which when user click on "Read More" then i need to show a bottom sheet.
Currently I added GestureDetector on whole ReadMore widget. Tap is working on whole but not on the "Read More" text.
So i just need to override the onTap click.
Looking forward your swift response.
Thanks
The text was updated successfully, but these errors were encountered: