如何使用Rawchip小部件打电话

发布于 2025-02-12 19:23:10 字数 1090 浏览 0 评论 0原文

基本上,我定义了一个数组列表,但是如何在标签上调用列表。有人可以帮我吗

@override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
            color: AppColor.white,
            width: MediaQuery.of(context).size.width,
            child: RawChip(
              showCheckmark: false, 
              label: Text(widget.list, 
              style: TextStyle(
                color: isSelected ? Colors.black : const Color.fromARGB(255, 45, 110, 162), 
                fontFamily: 'Poppins' 
              ),),
              backgroundColor: isSelected ? Colors.white : const Color.fromARGB(255, 200, 222, 255),
              shape: const StadiumBorder(
                side: BorderSide(color: Colors.transparent)),
      //selectedColor: Colors.red,
      selected: isSelected,
      onPressed: (){
        setState(() {
          isSelected = isSelected ? false : true;
        });
      },

Basically, I have define a list of array but how to call the list on the label. can someone help me
enter image description here

@override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
            color: AppColor.white,
            width: MediaQuery.of(context).size.width,
            child: RawChip(
              showCheckmark: false, 
              label: Text(widget.list, 
              style: TextStyle(
                color: isSelected ? Colors.black : const Color.fromARGB(255, 45, 110, 162), 
                fontFamily: 'Poppins' 
              ),),
              backgroundColor: isSelected ? Colors.white : const Color.fromARGB(255, 200, 222, 255),
              shape: const StadiumBorder(
                side: BorderSide(color: Colors.transparent)),
      //selectedColor: Colors.red,
      selected: isSelected,
      onPressed: (){
        setState(() {
          isSelected = isSelected ? false : true;
        });
      },

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2025-02-19 19:23:11

widget.variablename用于引用顶级小部件(statefulwidget)。要在州类中获取数据,只需

class MyWidget extends StatefulWidget {
  final int widgetData;
  const MyWidget({
    Key? key,
    required this.widgetData,
  }) : super(key: key);

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  final int stateData = 3;

    late int makingLocal;
    
    @override
    void initState() {
      super.initState();
      makingLocal = widget.widgetData;
    }
  @override
  Widget build(BuildContext context) {
    ...
  }
}

在您的情况下使用本地,它将只是列表。

  Container(
          child: Column(children: list),
        ),

widget.variableName is used to refer top level widget(StatefulWidget). To get data within state class, just use local

class MyWidget extends StatefulWidget {
  final int widgetData;
  const MyWidget({
    Key? key,
    required this.widgetData,
  }) : super(key: key);

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  final int stateData = 3;

    late int makingLocal;
    
    @override
    void initState() {
      super.initState();
      makingLocal = widget.widgetData;
    }
  @override
  Widget build(BuildContext context) {
    ...
  }
}

in your case it will be just list but.

  Container(
          child: Column(children: list),
        ),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文