美文网首页Flutter
Flutter按钮封装

Flutter按钮封装

作者: 笔头还没烂 | 来源:发表于2022-03-24 14:03 被阅读0次

代码如下:

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)),
              ),
            ),
          ],
        ),
      )),
    );
  }
}

相关文章

网友评论

    本文标题:Flutter按钮封装

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