You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter自定义文本样式位置报错及Bula ANVISA可点击链接实现问题

问题根因

Too many positional arguments: 0 allowed, but 1 found 报错由代码中多余的未闭合括号导致:你在Container的child属性、两个Material组件的child属性后额外写了左括号(,没有对应匹配的闭合右括号,Dart解析时会将括号内的内容判定为额外传入的位置参数,触发语法错误。
另外你代码里AppBar的Text组件fontFamily字段写了字体文件路径fonts/Quicksand-Light.ttf是错误的,该字段需要填写你在pubspec.yaml中声明的字体家族名称,不是文件物理路径。

功能实现方案

要实现「Bula ANVISA」居中、加粗、点击跳转的需求,按以下修改即可:

  • 删除所有多余括号修复语法报错
  • 用Center组件包裹该文本实现居中效果
  • 给文本的TextStyle添加fontWeight: FontWeight.bold属性实现加粗
  • 用InkWell组件包裹文本,在onTap回调中编写跳转对应在线文档的逻辑即可(跳转网页需要提前引入url_launcher依赖并配置对应平台权限,回调内替换为你自己的文档地址即可)
修复后完整代码
import 'package:flutter/material.dart';
// 如果使用url_launcher实现跳转,需要提前引入对应包
// import 'package:url_launcher/url_launcher.dart';

// 按照Dart命名规范,类名统一使用大驼峰格式
class Analgesicos extends StatefulWidget {
  const Analgesicos({Key? key}) : super(key: key);

  @override
  State<Analgesicos> createState() => _AnalgesicosState();
}

class _AnalgesicosState extends State<Analgesicos> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: Colors.teal,
        centerTitle: true,
        title: Text(
          'Analgésicos',
          style: TextStyle(
            // 此处替换为你在pubspec.yaml中声明的字体家族名
            fontFamily: 'Quicksand',
            fontSize: 22,
          ),
        ),
      ),
      body: Container(
        constraints: const BoxConstraints(minHeight: 0, maxHeight: 200.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const Padding(padding: EdgeInsets.only(top: 10, bottom: 10)),
            Center(
              child: Container(
                width: 240.0,
                height: 42.0,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(20.0),
                  color: const Color(0xffc5fce1),
                ),
                child: const Text(
                  'Não-opióides',
                  style: TextStyle(
                    fontFamily: 'Quicksand',
                    fontSize: 18,
                    color: Colors.black,
                    height: 1.7,
                  ),
                ),
              ),
            ),
            const Divider(height: 15),
            const Material(
              child: Card(
                child: ListTile(
                  title: Text('Ácido acetilsalicílico'),
                  subtitle: Text('''Apresentação: Comprimidos simples de 500 ou 650 mg
                Indicação: Antipirético e analgésico.
                Posologia odontológica: Uso interno (via oral)
                Tomar 1 comprimido de 6/6 horas.'''),
                ),
              ),
            ),
            Material(
              child: Card(
                color: Colors.white,
                child: InkWell(
                  // 点击跳转逻辑写在这里
                  onTap: () {
                    // 此处替换为你自己的在线文档跳转逻辑
                  },
                  child: const Padding(
                    padding: EdgeInsets.symmetric(vertical: 16),
                    child: Center(
                      child: Text(
                        'Bula ANVISA',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          fontSize: 16,
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

内容的提问来源于stack exchange,提问作者Pedro Henrique Cesar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 00:33:25