0

我正在制作一个颤振应用程序,供视力有限的人使用,并且我想让所有文本的大小与视口宽度一样大,达到指定的最大字体大小。实际的宽度和高度是动态的,所以我想使用媒体查询之类的东西来设置合理的大小。

我没有尝试过移动文本大小,我找不到任何对我有帮助的 SO 答案。

这是我现在尝试使用的代码,但它不起作用。

class HomeTabs extends StatefulWidget {
  const HomeTabs({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => HomeTabsState();
}

class HomeTabsState extends State<HomeTabs> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    User _user = Provider.of<User>(context, listen: false);

    return DefaultTabController(
    
      length: 2,
    
      child: Scaffold(

        drawer: AppDrawer(),
            
        appBar: AppBar(

          toolbarHeight: 100,
            
          iconTheme: IconThemeData(color: iconColor),
            
          backgroundColor: branding,

          centerTitle: true,

          title: FittedBox(

                       fit: BoxFit.contain,
                       
                       child: Text(_user.companyName),

                    ),
            
          bottom: TabBar(
            
            isScrollable: false,
            
            tabs:  [

              SizedBox(

                height: 100,
            
                 child:  Tab( 
                
                    child: FittedBox(

                      fit: BoxFit.contain,
                
                      child: Text( 'Notifications', style: tabStyle))
                
                  ),
              ),

              SizedBox(

                height: 100,

                child:  Tab( 

                  child: FittedBox(

                    fit: BoxFit.contain,
                
                    child: Text( 'Cases', style: tabStyle))
                
                ),
              ),
            ],
          ),
        ),
....
            
4

2 回答 2

1

对于标题使用容器是constraints这样的。

          title: Container(
            constraints: BoxConstraints(
                minWidth: MediaQuery.of(context).size.width - 50),
            child: FittedBox(
              child: Text(
                '_user.companyName',
              ),
            ),
          )

FittedBox对于选项卡只需交换Tab.

FittedBox(
                  child: Tab(
                    child: Text(
                      'Cases',
                    ),
                  ),
                ),
于 2022-02-28T14:02:17.110 回答
0

试试这个 App Bar Size 保持

PreferredSize(
            preferredSize: Size.fromHeight(100.0), // here the desired height
            child: AppBar(
              centerTitle: true,
              title: Text("Example"),
            )
        )

结果->在此处输入图像描述

于 2022-02-28T08:24:53.223 回答