openLink method

Future<void> openLink(
  1. BuildContext context,
  2. String url,
  3. String title
)

Handles external link opening with error feedback via TextToast.

This async method checks if the URL can be launched using canLaunchUrl, then launches it with launchUrl. If unsuccessful, it displays a toast notification with the error URL. Designed for seamless integration in interactive markdown like chat responses in ChatScreen or documentation in FillScreen. No state changes occur, ensuring efficient, non-blocking operation.

Implementation

Future<void> openLink(BuildContext context, String url, String title) async {
  if (await canLaunchUrl(Uri.parse(url))) {
    await launchUrl(Uri.parse(url));
  } else {
    TextToast("Could not open link: $url").open(context);
  }
}