美文网首页
flutter-按钮组件

flutter-按钮组件

作者: GitArtOS | 来源:发表于2024-10-08 16:07 被阅读0次
截屏2024-10-09 16.06.02.png

class Buttondemo extends StatefulWidget {
  const Buttondemo({super.key});

  @override
  State<Buttondemo> createState() => _ButtondemoState();
}

class _ButtondemoState extends State<Buttondemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("按钮组件"),
      ),
      body: Center(
        child: Column(
          children: [
            Padding(
              padding: const EdgeInsets.all(15.0),
              child: ElevatedButton(
                  onPressed: _onPressed, child: const Text("ElevatedButton")),
            ),
            FilledButton(
                onPressed: _onPressed, child: const Text("FilledButton")),
            FilledButton.tonal(
                onPressed: _onPressed, child: const Text("FilledButton.tonal")),
            FilledButton.tonalIcon(
                onPressed: _onPressed,
                label: const Text("FilledButton.tonalIcon")),
            OutlinedButton(
                onPressed: _onPressed, child: const Text("OutlinedButton")),
            TextButton(onPressed: _onPressed, child: const Text("TextButton")),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Ink(
                  decoration: const ShapeDecoration(
                      shape: CircleBorder(), color: Colors.blue),
                  child: IconButton(
                    onPressed: _onPressed,
                    iconSize: 30,
                    icon: const Icon(Icons.import_contacts),
                    color: Colors.white,
                  ),
                ),
                IconButton(
                    onPressed: _onPressed,
                    icon: const Icon(Icons.import_contacts),
                    iconSize: 30,
                    style: ButtonStyle(
                        backgroundColor:
                            PJButtonBackGroundColor(context, Colors.blue),
                        foregroundColor:
                            PJButtonBackGroundColor(context, Colors.white))),
              ],
            ),
            SizedBox(
              width: MediaQuery.of(context).size.width - 30,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  PJFilledButton(
                    onPressed: () {
                      print("置顶");
                    },
                    title: "置顶",
                    bgColors: ColorUtil.hexColorString("#F3AC31"),
                    fogColors: Colors.white,
                  ),
                  PJFilledButton(
                      onPressed: () {
                        print("优先推广了");
                      },
                      title: "优先推广",
                      bgColors: ColorUtil.hexColorString("#469DBF"),
                      fogColors: Colors.white),
                ],
              ),
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton.extended(
          onPressed: _onPressed,
          backgroundColor: Colors.blue,
          foregroundColor: Colors.white,
          label: const Text("FloatingActionButton.extended")),
    );
  }

  void _onPressed() {}
}

class PJFilledButton extends StatelessWidget {
  const PJFilledButton(
      {super.key,
      required this.title,
      required this.bgColors,
      required this.fogColors,
      this.onPressed});
  final String title;
  final Color bgColors;
  final Color fogColors;
  final VoidCallback? onPressed;
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 120,
      child: FilledButton(
        onPressed: onPressed,
        style: ButtonStyle(
            backgroundColor: PJButtonBackGroundColor(context, bgColors),
            foregroundColor: PJButtonBackGroundColor(context, fogColors)),
        child: Text(title),
      ),
    );
  }
}



相关文章

  • Flutter-按钮

    在 Flutter 里有很多的 Button,包括了:RaisedButton、FloatingActionBut...

  • 《Flutter For Android学习日记》基础控件-按钮

    Material组件库中的按钮 Material 组件库中提供了多种按钮组件如RaisedButton、FlatB...

  • 009--cc.Button

    1:添加按钮的方法(1)直接创建带Button组件的节点;(2) 先创建节点,再添加组件;2:按钮组件, 按钮是游...

  • Flutter-现有iOS工程引入Flutter

    Flutter-现有iOS工程引入Flutter Flutter-现有iOS工程引入Flutter

  • 六、bootstrap按钮、输入框

    知识点: 1、按钮组件2、输入框 1、按钮组件 1)基本的按钮组 2)按钮工具栏 3)按钮的大小 4)嵌套 5)垂...

  • Flutter-圆角按钮控件

    真的,只有在没事儿的时候写代码,内心才有一份舒服,特别是面朝大海的时候。 上图 形状在shape中定义:Shape...

  • flutter-列表滚动按钮

  • Flutter-虚线组件

    1.XFDashedLine效果展示 目的:实现效果的同时,提供定制,并且可以实现水平和垂直两种虚线效果: axi...

  • Flutter-基础组件

    前言 Flutter是Google开源的构建用户界面(UI)工具包,帮助开发者通过一套代码库高效构建多平台精美应用...

  • flutter-基础组件

    1.在Flutter中几乎所有的对象都是widget。2.在Flutter中widget的作用是描述一个UI元素的...

网友评论

      本文标题:flutter-按钮组件

      本文链接:https://www.haomeiwen.com/subject/ihebrjtx.html