简体   繁体   中英

How to change font color in Flutter?

I want make it so when the menu is selected outside the white borders the font color of the letter changes to black instead of white, I tried to change it but I couldn't, if someone takes a look at the code would know where to put the adjustment?

ListView.builder(
  scrollDirection: Axis.vertical,
  shrinkWrap: true,
  itemCount: controller.items.length,
  itemBuilder: (_, index) {
    final _item = controller.items[index];
    if(_item['rota'] == Routes.home){
      return Obx(() => Container(
        decoration: (controller.selectedIndex == index)
            ? const BoxDecoration(
              border: Border(
                top: BorderSide(width: 3.0, color: Colors.white),
                bottom: BorderSide(width: 3.0, color: Colors.white),
              ),
            )
            : null,
        child: Obx(() =>  Card(
          color: const Color(0XFF007E94),
          elevation: 3,
          child: ListTile(
            title: Text(
              _item['titulo'],
              style: const TextStyle(color: (controller.selectedIndex == index ) ? Colors.black :  Colors.white),
            ),
            leading: _item['icone'],
              onTap: () {
                controller.selectedIndex = index ;
                Get.toNamed(_item['rota']);
              },
              selected: controller.selectedIndex == index
          ),
        )),
      ));
    }
  }
),

I tried this way but still can't adjust

在此处输入图像描述

Try below code, remove const keyword for TextStyle

title: Text(
              _item['titulo'],
              style: TextStyle(color: (controller.selectedIndex == index ) ? Colors.black :  Colors.white),
            ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM