Load a widget from a map or list

Related searches

I have a very long list of report widgets that basically define a layout of data. I Want to be able to dynamically load those widgets from some other way that do conditional (if/else) or switches.

class ReportLibrary {
  final data;
  ReportLibrary(this.data);

  Map<String,Widget> _library = {
    'QuestionsAndScores': QuestionScoresView,
  };

  Widget get(String key){
    return _library[key](data);
  }
}

I'm not sure if this is possible or there is a better way.

Here is the errors:

flutter: Attempted to use type 'QuestionScoresView' as a function. Since types do not define a method 'call',
flutter: this is not possible. Did you intend to call the QuestionScoresView constructor and forget the 'new'
flutter: operator?

You are trying to create string to subclass map - and then instantiate an instance of the subclass. This isn't allowed in Dart without mirrors, which you cannot use in Flutter.

Why wouldn't you use a switch? It's a little more verbose, but would work.

Widget get(String key) {
  case 'QuestionsAndScores':
    return QuestionScoresView(data);
  // etc
}

Equally, you could have a map of string to function:

  final _library = <String, Function>{
    'QuestionsAndScores': (data) => QuestionScoresView(data),
  };

  Widget foo = _library['QuestionsAndScores'](data);

Creating a list of widgets from map with keys and values, Update answer to incorporate @lrn 's comment. You can use map const optionsMap = { 111:"First option", 222:"Second option", } return SimpleDialog( title:� Instead of immediately rendering an interactive map which might slow down your site, Google Maps Widget will allow you to use a thumbnail image of your map which loads in a blink of an eye. Instead of loading the map as soon as the page loads (which usually takes about 70 requests and 1 MB of transferred data) the plugin loads a map as one

The syntax you are using for entering value to the map is wrong, it is used to refer a function in flutter and so your error message says so.

you should change this:

Map<String,Widget> _library = {
  'QuestionsAndScores': QuestionScoresView,
};

to something like this:

Map<String,Widget> _library = {
  'QuestionsAndScores': QuestionScoresView(),
};

I hope it helps, let me know if you have any doubts.

List widget—ArcGIS Experience Builder, You can use the List widget on a page with or without a displayed map. If you include Paging style—Define how to load list items that don't fit on the first page :. If you need to add the widget to the app first, click a widget placeholder on the Widget tab. In the Choose Widget window that opens, select the widget and click OK. Check or uncheck the Highlight location check box. When this check box is checked, the location highlights on the map.

Actually you are trying to make a call from Map value, that's what the error message says:

Change:

return _library[key](data);

to:

return _library[key];

This is how you access map value: _library[key].

Update:

Make sure your Map value is Widget and add paranthesis() to QuestionScoresView otherwise you are assinging the Type. That will causes the error message that you commented(The element type 'Type' can't be assigned to the map value type 'Widget').

class

ReportLibrary {
    final data;
    Map<String, Widget> _library;
    ReportLibrary(this.data) { 
        _library = {
            'QuestionsAndScores': QuestionScoresView(),
        };
    }

  Widget get(String key){
    return _library[key];
  }
}

Map widget—ArcGIS Experience Builder, The Map widget allows you to display 2D and 3D geographic information. You have a requirement to filter a List widget based on clicking a feature on the map. Initial view—The initial position of the map when it loads in the widget. I have a Stateful Widget containing a custom tab view. At the initialisation of the widget, category data(All, Science, Trending, Health &amp; Fitness here) is fetched from the firestore and accord

WP Google Maps – WordPress plugin, List your map markers in the four ways; basic list, basic table, carousel, Move your marker list inside the map window; Multiple map widget functionality; Add� How To Pay Off Your Mortgage Fast Using Velocity Banking | How To Pay Off Your Mortgage In 5-7 Years - Duration: 41:34. Think Wealthy with Mike Adams Recommended for you

Widget List — Jupyter Widgets 7.5.1 documentation, There are many widgets distributed with ipywidgets that are designed to display IntProgress( value=7, min=0, max=10, step=1, description='Loading:', The . value traitlet is now a list of dictionaries, rather than a dictionary mapping the� Posts Widget (Pro) With the Posts Widget you can display a list of any post types, including custom post types, in various layouts and ways. This practical widget can be used to display posts from a particular category or other taxonomy, recent posts, and more.

To start using it, you must load the template tag in the template you want to use its functions: {% load widget_tweaks %} Now expand your form by iterating through its fields, in order to expose the input tags, replacing this: {{ form }} For this:

Comments
  • This is what I was trying to avoid. Since this list is going to be about 40 long
  • But how is that different from a map with 40 entries?
  • Don't worry about performance. The compiler will create code that switches on the hash of the key string under the hood.
  • If I do that I get: error: The element type 'Type' can't be assigned to the map value type 'Widget'. (map_value_type_not_assignable at [*] lib/ui/views/reports/report_library.dart:9)
  • @JasonSpick what is the type of QuestionScoresView. It have to be a type of widget or child of it
  • It is a StatelessWidget
  • @JasonSpick If it is a stateless widget you have to create a instance as value QuestionScoresView(). Otherwise Map try to get the value as Type. Let me know if this fix your problem.
  • QuestionScoresView requires data to be passed. I then get:Only static members can be accessed in initializers