KingWu / gen_lang

gen_lang is a dart library for internationalization. Extracts messages to generate dart files required by Intl, inspired by Intl_translation and Flutter i18n
BSD 2-Clause "Simplified" License
100 stars 23 forks source link

Usage in BottomNavigationBarItem #6

Closed Pexeed closed 5 years ago

Pexeed commented 5 years ago

Hello,

First thank you for the good library!

I'm facing an issue when trying to set a BottomNavigationBarItem Title.

BottomNavigationBarItem(
                icon: Icon(Icons.dialpad),
                title: new Text( S.of(context).example )
              )

It throws the following errors:

Invalid constant value.

The values in a const list literal must be constants. Try removing the keyword 'const' from the list literal.

Arguments of a constant creation must be constant expressions. Try making the argument a valid constant, or use 'new' to call the constructor

Using a simple string, such as Text('Test') it works.

Do you think it's possible to solve this issue?

Thank you!

KingWu commented 5 years ago

@Pexeed i try your code. Did not find your issues. Can you provide more codes to me to find out the issues

Pexeed commented 5 years ago

Sure the build method is the following:

@override
  Widget build(BuildContext context) {

    if (_viewModel == null)
      _viewModel = BarTabSelectionViewModel(context);

    return
    SafeArea(child:
      Scaffold(
          resizeToAvoidBottomInset: true,
          key: scaffoldKey,
          appBar: AppBar(
            title: Image.asset('assets/images/logo.png', height: 30,),
            backgroundColor: Colors.black,
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.exit_to_app, color: Colors.white,),
                onPressed: _doLogoff,
              )
            ],
          ),
          body: _selectors.elementAt(_selectedIndex),

          bottomNavigationBar: BottomNavigationBar(
            currentIndex: _selectedIndex,
            backgroundColor: Colors.black,
            unselectedItemColor: Colors.white,
            selectedItemColor: Theme.of(context).accentColor,
            onTap: _onItemTapped,
            items: const <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                icon: Icon(Icons.dialpad),
                title: Text('Comanda')
              ),
              BottomNavigationBarItem(
                icon: Icon(Icons.border_all),
                title: Text('Lista'),
              ),
            ],
          ),
      )
    );
  }

I just found out the issue, the items: const <BottomNavigationBarItem>.

I removed const <BottomNavigationBarItem> and now it works, it's not an issue with the library, sorry and thanks for the quick reply!