Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can text in a Flutter web app be made searchable?

Problem: When I run a Flutter app as a web app in a browser, I can use the browser's text search function Ctrl + F to search for text on the page. The search function finds all of the instances of the search term that are currently shown on screen, but it does not find all of the other instances of the text that are currently out of view.

Example: In the example below I am searching for the word tile, which is used 8 times in total: 4 times in the blue tiles and another 4 times in the purple tiles. However, when I search for the word tile, the browser only finds the 4 instances of the word that are currently shown on the screen at the time of the search. It ignores all instances of the word that are not rendered on the screen at the time of the search.

enter image description here

Documentation: The Flutter and Dart documentation does not have any information on searchable text and I do not see any other similar widgets or properties available.

Attempts: I have tried using a SelectableText widget, but the same problem persists.

like image 869
Benoît Cerise Avatar asked Jun 18 '20 10:06

Benoît Cerise


People also ask

Is Flutter good for web apps?

The extensive features of Flutter make it one of the best choices for the development of native apps for Android and iOS. With Flutter web development, designing applications across different platforms become a streamlined, smooth process.

Can a Flutter app run on web?

Flutter for web is a code-compatible implementation of Flutter that is rendered using standards-based web technologies: HTML, CSS and JavaScript. With Flutter for web, you can compile existing Flutter code written in Dart into a client experience that can be embedded in the browser and deployed to any web server.

Is Flutter website written in Flutter?

Since Flutter is written in Dart, a language that offers JavaScript compilation, it was a natural next step to explore the web as a target. This also builds towards our vision of providing a portable framework for building beautiful UI wherever you want to paint pixels.


1 Answers

You can use element = document.getElementById('searchable_text') and element.textContent || a.innerText. See JavaScript tutorial on W3Schools.

Resources:

  • To create a list and assign it an Id, look at Get Started from Dart docs.
  • To select elements of the HTML document, read querySelector on Dart docs.

Tell us what worked for your!

like image 86
Guillem Puche Avatar answered Sep 19 '22 12:09

Guillem Puche