0

This is the code: Have changed title to label as below. But Text(....) was all highlighted in red. Error - "the argument type 'Text' can't be assigned to the parameter type 'String'."

    @override
 Widget build(BuildContext context) {
        var data = EasyLocalizationProvider.of(context).data;
  return EasyLocalizationProvider(
          data: data,
      child: Scaffold(
     body: callPage(currentIndex),
     bottomNavigationBar: Theme(
         data: Theme.of(context).copyWith(
             canvasColor: Colors.white,
             textTheme: Theme.of(context).textTheme.copyWith(
                 caption: TextStyle(color: Colors.black26.withOpacity(0.15)))),
         child: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: currentIndex,
          fixedColor: Color(0xFF6991C7),
          onTap: (value) {
           currentIndex = value;
           setState(() {});
          },
BottomNavigationBarItem(
               icon: Icon(Icons.shop),
               label: Text(
                 AppLocalizations.of(context).tr('Produce'),
                style: TextStyle(fontFamily: "Berlin", letterSpacing: 0.5),
               )),

Error image

Jix Tang
  • 49
  • 1
  • 6

3 Answers3

0

BottomNavigationBarItem's lable reveive String type, not Text.

enter image description here

聂超群
  • 1,659
  • 6
  • 14
  • How would I format the code to receive string type ? When I am remove text; I get error in the style: TextStyle(fontFamily: "Berlin", letterSpacing: 0.5), – Jix Tang Aug 19 '22 at 00:39
  • Change `lable: Text(...` to `label: AppLocalizations.of(context).tr('Produce')` should be fine. – 聂超群 Aug 19 '22 at 00:40
  • Yes I did change that; but got error in the style: TextStyle(fontFamily: "Berlin", letterSpacing: 0.5), - style was highlighted in red... The named parameter 'style' isn't defined. – Jix Tang Aug 19 '22 at 00:42
  • You should replace whote Text with `AppLocalizations.of(context).tr('Produce')` – 聂超群 Aug 19 '22 at 00:46
  • Checked my another answer? (I can not type all info in comment) – 聂超群 Aug 19 '22 at 00:48
0

Try replace

label: Text(
   AppLocalizations.of(context).tr('Produce'),
   style: TextStyle(fontFamily: "Berlin", letterSpacing: 0.5),
),

with

label: AppLocalizations.of(context).tr('Produce')
聂超群
  • 1,659
  • 6
  • 14
0

Check in the documentation, the label is a string? and not a widget. Link : https://api.flutter.dev/flutter/widgets/BottomNavigationBarItem-class.html So you have to change it like this:

label: AppLocalizations.of(context).tr('Produce')