flutter3重构按钮

import 'package:flutter/material.dart';
class MyButton extends StatelessWidget {
  const MyButton({super.key});

  @override
  Widget build(BuildContext context) {
    //return const Placeholder();
 //具体内容开始
    return Column(
      children: [
        //const TextField(),
        //文本框输入开始
        const TextField(
          decoration: InputDecoration(
              border: OutlineInputBorder(),
              hintText: "请输入查询地址。"),
        ),
        //文本框输入结束
        //
        buildMaterialButton() //重构按钮
      ],
    );//注意最后一个是冒号
  //具体内容结束
  }

  MaterialButton buildMaterialButton() {
    return MaterialButton(
        //
        textColor: Colors.white,
        color: Colors.green,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
        onPressed: () {
          print('按钮被点击');
        },
        child: const Text('位置'),
      );
  }
}

  

posted @ 2024-06-27 15:01  飞雪飘鸿  阅读(5)  评论(0编辑  收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL