Flutter按钮封装

代码如下:

import 'package:flutter/material.dart';

class QXButton extends StatelessWidget {
  QXButton({required this.gestureDetector});

  final Widget gestureDetector;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Container(
      padding: EdgeInsets.all(8.0),
      height: 40,
      width: 120,
      decoration: BoxDecoration(
          color: Colors.blue, borderRadius: new BorderRadius.circular(5.0)),
      child: this.gestureDetector,
    );
  }
}

外部调用代码如下:

import 'package:flutter/material.dart';
import 'QXButton.dart';

class MyHome extends StatelessWidget {
  final initTitle = "初始化";

  final margin = new Container(
    height: 30,
  );
  final textStyle = const TextStyle(color: Colors.white, fontSize: 14.0);
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      body: new Center(
          child: new Container(
        padding: EdgeInsets.all(100),
        child: new Column(
          children: [
            new QXButton(
              gestureDetector: new GestureDetector(
                onTap: () => {print("初始化")},
                child: new Center(child: new Text(initTitle)),
              ),
            ),
          ],
        ),
      )),
    );
  }
}
知识

解决 WKWebView 刘海机型不全屏显示的问题 iOS

2024-12-11 13:27:28

知识

Flutter 锦囊集

2024-12-11 13:27:32

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索