GitHub 代码仓version-two/flutter_imagebutton

flutter_imagebutton

用于 Flutter 的图像按钮

flutter_imagebutton 项目封面
星标
6
复刻
5
最近推送(UTC)
2024年12月13日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

ImageButton

A customizable button widget composed of two images.

About

ImageButton is a simple plugin that allows you to create buttons using images with two states: pressed and unpressed. It is designed for use cases where you want a button that visually responds to user interaction with images.


How to Use ImageButton

Widget build(BuildContext context) {
  return ImageButton(
    child: Row(
      children: [
        Icon(Icons.star, color: Colors.white),
        Text("Click Me", style: TextStyle(color: Colors.white))
      ],
    ),
    width: 100,
    height: 50,
    pressedImage: Image.asset("assets/pressed.png"),
    unpressedImage: Image.asset("assets/unpressed.png"),
    onTap: () {
      print('Button pressed!');
    },
  );
}

ImageButton Properties

Property Type Description
child Widget? Custom widget to display inside the button. Preferred over children.
children List<Widget> Widgets to be displayed inside the button (deprecated, use child instead).
unpressedImage Image The image displayed when the button is not pressed.
pressedImage Image The image displayed when the button is pressed.
label Widget? An optional label widget displayed below the button.
onTap VoidCallback? Callback function triggered when the button is tapped.
width double? Width of the button.
height double? Height of the button.
mainAxisAlignment MainAxisAlignment How the children are aligned horizontally. Default is MainAxisAlignment.center.
crossAxisAlignment CrossAxisAlignment How the children are aligned vertically. Default is CrossAxisAlignment.center.
isEnabled bool Determines if the button is interactable. Default is true.
isLoading bool Shows a loading indicator if set to true. Default is false.
loadingIndicator Widget? Custom widget to show as the loading indicator. Defaults to CircularProgressIndicator().
loadingColor Color? Color of the loading indicator if isLoading is set to true. Defaults to null.

Example Use Case

Here is an example showcasing how to use ImageButton in a practical scenario:

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text("ImageButton Example")),
        body: Center(
          child: ImageButton(
            child: Row(
              children: [
                Icon(Icons.thumb_up, color: Colors.white),
                SizedBox(width: 5),
                Text("Like", style: TextStyle(color: Colors.white))
              ],
            ),
            width: 120,
            height: 50,
            pressedImage: Image.asset("assets/button_pressed.png"),
            unpressedImage: Image.asset("assets/button_unpressed.png"),
            isLoading: false,
            onTap: () {
              print("Button Pressed");
            },
          ),
        ),
      ),
    );
  }
}

Example Animation

Below is an example animation of the ImageButton in action:

Example Animation


Contributions

Contributions are welcome! Feel free to fork the repository and submit a pull request for any enhancements or bug fixes.


License

This project is licensed under the MIT License. See the LICENSE file for details.

Version Two s.r.o. GitHub avatar
GitHub 作者

Version Two s.r.o. ↗

Version Two - Digital advertising agency focusing on web and mobile app development

Bratislava, Slovakia官方网站 ↗
语言DartKotlinSwiftRubyObjective-C

分类

此仓库发布的插件

使用的依赖

依赖清单 3 项

  • flutter{"sdk":"flutter"}
  • flutter_test开发依赖{"sdk":"flutter"}
  • flutter_lints开发依赖^2.0.0

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗