pub fn LinkedText(
text: AnnotatedString,
modifier: Modifier,
style: TextStyle,
open_url: impl Fn(&str) + 'static,
) -> NodeIdExpand description
Renders an AnnotatedString and automatically dispatches link clicks:
LinkAnnotation::Url→ callsopen_url(url)(platform provides the URI handler).LinkAnnotation::Clickable→ calls the handler stored in the annotation.
§Example — opening a URL
ⓘ
let uri_handler = local_uri_handler().current();
let text = AnnotatedString::builder()
.append("Visit the ")
.with_link(
LinkAnnotation::Url("https://developer.android.com/".into()),
|b| b.append("Android Developers"),
)
.append(" site.")
.to_annotated_string();
LinkedText(
text,
Modifier::empty(),
TextStyle::default(),
move |url| { uri_handler.open_uri(url).ok(); },
);§Example — custom action (LinkAnnotation::Clickable)
ⓘ
let text = AnnotatedString::builder()
.append("Click ")
.with_link(
LinkAnnotation::Clickable {
tag: "action".into(),
handler: Rc::new(move || println!("clicked!")),
},
|b| b.append("here"),
)
.to_annotated_string();
// open_url is never called for Clickable — pass a no-op.
LinkedText(text, Modifier::empty(), TextStyle::default(), |_| {});§JC parity
Equivalent to Text(buildAnnotatedString { withLink(LinkAnnotation.Url(…)) { … } }).
The open_url parameter corresponds to the platform-provided LocalUriHandler.