The url_launcher has a built-in possibility to control the way the URL is opened.įor this, the launchUrlString() and launchUrl function offers an optional mode argument, which expects a type LaunchMode. In any case, as a developer, it’s useful to know, how to trigger which behavior. In an external application the user can choose (e.In the currently running app as a modal (e.In the currently running app as a new page (using the navigation stack).In the OS-specific default browser (e.Inside a mobile app, things are more complicated.Ī user could expect different places for the link to be opened: Since we are already in the context of an application whose main purpose is to display websites (the browser), the only necessary decision is whether to display it in the existing window or create a new one (e. The concept of launching an URL when the user taps it is pretty clear on the web. The code produces the following result: Behavior of our inline link using flutter_linkify Ways of launching \n ' 3 'We can \' t disguise the link: ', This enables us to react on the user interacting with the text with a gesture.Ģ text: 'This way we can embed a link into a paragraph. Lucky for us, the TextSpan widget has a recognizer property. It creates a subtree with a list of TextSpan widgets. In order to combine differently styled texts in one widget, the RichText widget can be used. The latter can be used for dynamic user generated content like chat messages or something that is loaded during runtime via a web API. The former is great for things like help messages that contain a web link. Static linking means that the whole text is known at development time and the hyperlinks are set manually.ĭynamic linking is the opposite: instead of knowing beforehand where links are, these are created during runtime by analysing a text and looking for containing web links. We can either do a static or a dynamic linking. Instead, you want the link to be embedded inline like an tag in the web within a paragraph. Sometimes you don’t want the whole text to be a link. This is how it looks like: Behavior of our standalone link Inline texts We are going to talk about this in detail in the chapter Was of launching. Note that we are using the url_launcher package to launch the browser. The whole buttons is linked to a website and tapping the button connects the user via the default browser to that website. The “standalone” approach is to provide a weblink to an app user is by creating a button that contains a Text widget whose style mimics the well-known hyperlink style. Let’s have a look at how we can achieve both ways of linking. A word or phrase that is linked inside a text paragraph - often with its characteristic styling: blue and underlined. This is something you see more often in apps because the finger needs bigger areas to interact than mouse cursors.Īnother way that is mostly seen on websites is an inline link. One way is to make a whole widget like InkWell or TextButton a link. There are different ways in which a Flutter widget can be linked to a website. Let’s discuss how to create hyperlinks inside of widgets. In the web context, creating links is as easy as utilizing an tag.Īs hyperlinks are an integral part of the web platform, this is one of the first things you learn to implement as a developer and to make use of as a user.įlutter foremost being a UI framework is not so much connected to hyperlinks. Use flutter_linkify for dynamic links (like in chat messages or other user generated content).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |