Home > Enterprise >  type '(dynamic) => Set<Text>' is not a subtype of type '(String, String) =&g
type '(dynamic) => Set<Text>' is not a subtype of type '(String, String) =&g

Time:12-16

I am new to flutter. I have userData that starts off as a blank dictionary and as users continue through the page it will fill up for example:

var userData = {
"Color": "muted",
"Size": "42",
}

I would like to map these out into text at the bottom of the page for the user to see

Your selected style/sizes
Color: muted
Size: 42

Here is my current code for this component and I am using provider to grab userData:

Visibility(
              visible:
                  context.watch<HomeProvider>().userData == {} ? false : true,
              child: Padding(
                padding: const EdgeInsets.only(left: 10.0),
                child: SizedBox(
                  width: MediaQuery.of(context).size.width,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      const Text(
                        'Your selected style/sizes',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 12,
                        ),
                      ),
                      Column(
                        children: context.watch<HomeProvider>().userData == {}
                            ? []
                            : context.watch<HomeProvider>().userData.map(
                                  (e) => {
                                    Text(e),
                                  },
                                ),
                      ),
                    ],
                  ),
                ),
              ),
            )

But whatever I try to do to display the data I get this error

The following _TypeError was thrown building HomePage(dirty, dependencies: [MediaQuery, _InheritedProviderScope<HomeProvider?>], state: HomePageState#d145b):
type '(dynamic) => Set<Text>' is not a subtype of type '(String, String) => MapEntry<dynamic, dynamic>' of 'transform'

which is being cause by the line with .map()

CodePudding user response:

Since userData is a map, you need first to get the entries, this will solve your problem:

context.watch<HomeProvider>().userData.entries.map<Widget>((e) => Text(e.value)).toList()
  • Related