123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /*
- * @Author : WuWei
- * @LastEditors : WuWei
- * @Date : 2022-08-17 23:04:42
- * @LastEditTime : 2022-08-17 23:06:27
- * @Description : Do not edit
- */
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- /// Icon button widget built different
- /// depends on [MaterialApp] or [CupertinoApp] ancestor.
- class IconBtn extends StatelessWidget {
- /// Widget to use inside button.
- ///
- /// Typically [Icon] widget.
- final Widget? icon;
- /// Function called when user tap on the button.
- ///
- /// Can be null. In this case button will be disabled.
- final VoidCallback? onTap;
- /// Tooltip for button.
- ///
- /// Applied only for material style buttons.
- /// It means only if widget has [MaterialApp] ancestor.
- final String? tooltip;
- /// Creates button with [icon] different
- /// depends on [MaterialApp] or [CupertinoApp] ancestor.
- const IconBtn({Key? key, required this.icon, this.onTap, this.tooltip})
- : super(key: key);
- @override
- Widget build(BuildContext context) {
- // ignore: unnecessary_null_comparison
- bool isMaterial = Material.of(context) != null;
- return isMaterial ? _materialBtn() : _cupertinoBtn();
- }
- Widget _cupertinoBtn() => CupertinoButton(
- padding: const EdgeInsets.all(0.0),
- child: icon!,
- onPressed: onTap,
- );
- Widget _materialBtn() => IconButton(
- icon: icon!,
- tooltip: tooltip!,
- onPressed: onTap,
- );
- }
|