首页 > 解决方案 > Flutter ConvexAppBar 如何改变文字样式?

问题描述

当我尝试更改 TextStyle 时,它​​显示“无法将参数类型‘文本’分配给参数类型‘字符串’。” 我怎样才能改变它?

  1. 我正在使用convex_bottom_bar 3.0.0
  2. 如果我弄错了,对不起我的英语
 bottomNavigationBar: ConvexAppBar(
          items: [
            TabItem(icon: Icons.touch_app_rounded, title: Text("Tab1",style: TextStyle(fontFamily: "iransans"),)),
            TabItem(icon: Icons.store_rounded, title: 'Mağaza'),
            TabItem(icon: Icons.developer_board_rounded, title: 'Simülasyon'),
            TabItem(icon: Icons.timeline_rounded, title: 'İstatistik'),
            TabItem(icon: Icons.view_week_rounded, title: 'Diğer'),
          ],
          gradient: LinearGradient(
            colors: [Color(0xFFEC407A),
              Color(0XFF1A237E)],
            begin: Alignment.bottomCenter,
            stops: [
              0.0,0.4
            ],
            end: Alignment.topCenter,
          ),
          height: 70,
          backgroundColor: Color(0xFFEC407A),
          //backgroundColor: Colors.white,
          activeColor: Colors.white,
          initialActiveIndex: 0,//optional, default as 0
          onTap: (int i) => print('click index=$i'),
        ),

标签: flutterflutter-bottomnavigationconvex-bottom-bar

解决方案


//Don't use Text () and use the StyleProvider Widget in your bottomNavigationBar. In 
//TextStyle add fontFamily.

bottomNavigationBar: StyleProvider(    
  style: Style(),
  child: ConvexAppBar(
    initialActiveIndex: 1,
    height: 50,
    top: -30,
    curveSize: 100,
    style: TabStyle.fixedCircle,
    items: [
      TabItem(icon: Icons.link),
      TabItem(icon: Icons.import_contacts),
      TabItem(title: "2020", icon: Icons.work),
    ],
    backgroundColor: _tabBackgroundColor,
  ),
)
class Style extends StyleHook {
  @override
  double get activeIconSize => 40;

  @override
  double get activeIconMargin => 10;

  @override
  double get iconSize => 20;

  @override
  TextStyle textStyle(Color color) {
    return TextStyle(fontSize: 20, color: color);
  }
}

推荐阅读