Flutter仿拟物风格按钮插件neumorphic_button的使用
Flutter仿拟物风格按钮插件neumorphic_button的使用
本README描述了该包。如果你将此包发布到pub.dev,则此README的内容将出现在你的包的首页上。
有关编写好的包README的指南,请参阅 编写包页面。
有关开发包的一般信息,请参阅Dart指南 创建库包 和 Flutter指南 开发包和插件。
Neumorphic Button
这个包让你可以创建具有多种可定制功能的仿拟物风格按钮,这些功能可以在你的Flutter应用中使用。你可以创建一种极简视觉设计风格,使用单色颜色、微妙阴影和低对比度来展示按钮和卡片,创造出非常柔和的效果。
安装
- 在你的
pubspec.yaml
文件中添加最新版本的包。
dependencies:
neumorphic_button: ^0.0.1+2
- 导入包并在你的Flutter应用中使用它。
import 'package:neumorphic_button/neumorphic_button.dart';
特性
你可以为你的仿拟物按钮指定以下属性:
height
width
border-radius
box-shape
shadow-color
spread-radius
blur-radius
onTap function
示例
轻模式仿拟物按钮
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.grey.shade300,
body: Center(
child: NeumorphicButton(
onTap: () {},
child: Image.asset(
'assets/apple.png',
height: 80,
color: Colors.grey[700],
),
borderRadius: 12,
bottomRightShadowBlurRadius: 15,
bottomRightShadowSpreadRadius: 1,
borderWidth: 5,
backgroundColor: Colors.grey.shade300,
topLeftShadowBlurRadius: 15,
topLeftShadowSpreadRadius: 1,
topLeftShadowColor: Colors.white,
bottomRightShadowColor: Colors.grey.shade500,
height: size.width * 0.5,
width: size.width * 0.5,
padding: EdgeInsets.all(50),
bottomRightOffset: Offset(4, 4),
topLeftOffset: Offset(-4, -4),
)),
);
}
}
暗模式仿拟物按钮
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.grey.shade900,
body: Center(
child: NeumorphicButton(
onTap: () {},
child: Image.asset(
'assets/apple.png',
height: 80,
color: Colors.grey[700],
),
borderRadius: 12,
bottomRightShadowBlurRadius: 15,
bottomRightShadowSpreadRadius: 1,
borderWidth: 5,
backgroundColor: Colors.grey.shade900,
topLeftShadowBlurRadius: 15,
topLeftShadowSpreadRadius: 1,
topLeftShadowColor: Colors.grey.shade800,
bottomRightShadowColor: Colors.black,
height: size.width * 0.5,
width: size.width * 0.5,
padding: EdgeInsets.all(50),
bottomRightOffset: Offset(5, 5),
topLeftOffset: Offset(-5, -5),
)),
);
}
}
更多关于Flutter仿拟物风格按钮插件neumorphic_button的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter仿拟物风格按钮插件neumorphic_button的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是一个关于如何在Flutter项目中使用neumorphic_button
插件来创建仿拟物风格按钮的示例代码。
首先,确保你已经在pubspec.yaml
文件中添加了neumorphic_button
依赖项:
dependencies:
flutter:
sdk: flutter
neumorphic_button: ^x.y.z # 请替换为最新版本号
然后,运行flutter pub get
来安装依赖。
接下来,你可以在你的Flutter项目中创建一个仿拟物风格的按钮。以下是一个完整的示例,包括一个主屏幕,其中包含一个Neumorphic风格的按钮:
import 'package:flutter/material.dart';
import 'package:neumorphic_button/neumorphic_button.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Neumorphic Button Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: NeumorphicButtonDemo(),
);
}
}
class NeumorphicButtonDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Neumorphic Button Demo'),
),
body: Center(
child: NeumorphicButton(
onPressed: () {
// 按钮点击事件处理
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Button Pressed!')),
);
},
child: Text(
'Neumorphic Button',
style: TextStyle(color: Colors.white),
),
padding: EdgeInsets.all(16.0),
color: Colors.grey[800]!,
borderColor: Colors.grey[700]!,
borderRadius: BorderRadius.circular(20),
depth: 10,
),
),
);
}
}
在这个示例中,我们创建了一个简单的Flutter应用,其中包含一个主屏幕NeumorphicButtonDemo
。在这个屏幕上,我们使用NeumorphicButton
创建了一个仿拟物风格的按钮。
NeumorphicButton
的参数解释如下:
onPressed
:按钮点击事件处理函数。child
:按钮中的文本或图标。padding
:按钮内边距。color
:按钮的背景颜色。borderColor
:按钮的边框颜色。borderRadius
:按钮的圆角半径。depth
:按钮的立体深度,正值表示按钮凸起,负值表示按钮凹陷。
你可以根据需要调整这些参数来创建符合你设计要求的按钮。
希望这个示例对你有帮助!如果你有任何其他问题,请随时提问。