Flutter拟物化UI设计插件flutter_neumorphism_ui的使用
Flutter拟物化UI设计插件flutter_neumorphism_ui的使用
Flutter拟物化设计简介
Aesthetic Appeal(美学吸引力)
创建一个现代化、简洁且视觉上令人愉悦的界面,使其感觉触感丰富且吸引人。
User Experience(用户体验)
模仿物理表面,使用户界面更加直观和熟悉。
Customization(定制化)
提供创意控制,以实现独特且具有区分度的应用程序设计。
Stand Out(脱颖而出)
通过采用时尚的未来主义设计元素帮助应用程序脱颖而出。
Neumorphism(拟物化设计)
在扁平化和仿生设计之间取得平衡,使其成为追求极简主义但又带有深度的应用程序的有效选择。
示例代码
主文件
import 'package:example/card_items.dart';
import 'package:example/items.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
[@override](/user/override)
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.grey.shade300,
),
useMaterial3: true,
),
home: Scaffold(
appBar: AppBar(
title: const Text("Neu morphism"),
),
backgroundColor: Colors.grey.shade300,
body: Container(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Expanded(child: myWidget(context)),
Expanded(
child: ListView.builder(
itemCount: 5,
itemBuilder: (BuildContext context, int index) {
return Items(width: size.width);
}),
),
],
),
),
));
}
Widget myWidget(BuildContext context) {
Size size = MediaQuery.of(context).size;
return MediaQuery.removePadding(
context: context,
removeTop: true,
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemCount: 4,
itemBuilder: (BuildContext context, int index) {
return CardItems(width: size.width);
}),
);
}
}
卡片组件
import 'package:flutter/material.dart';
class CardItems extends StatelessWidget {
final double width;
const CardItems({required this.width, super.key});
[@override](/user/override)
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: FlutterNeumorphisms(
onTap: () {},
borderRadius: 12,
bottomRightShadowBlurRadius: 15,
bottomRightShadowSpreadRadius: 1,
borderWidth: 5,
backgroundColor: Colors.grey.shade300,
topLeftShadowBlurRadius: 15,
topLeftShadowSpreadRadius: 1,
topLeftShadowColor: Colors.white,
bottomRightShadowColor: Colors.grey.shade500,
height: 100,
width: width,
bottomRightOffset: const Offset(4, 4),
topLeftOffset: const Offset(-4, -4),
child: const Row(
children: [
Icon(Icons.opacity_rounded, size: 30),
SizedBox(width: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Drop", style: TextStyle(fontSize: 20)),
Text("Neu morphism", style: TextStyle(fontSize: 18)),
],
),
],
),
),
);
}
}
列表项组件
import 'package:flutter/material.dart';
class Items extends StatelessWidget {
final double width;
const Items({required this.width, super.key});
[@override](/user/override)
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: FlutterNeumorphisms(
onTap: () {},
borderRadius: 12,
bottomRightShadowBlurRadius: 15,
bottomRightShadowSpreadRadius: 1,
borderWidth: 5,
backgroundColor: Colors.grey.shade300,
topLeftShadowBlurRadius: 15,
topLeftShadowSpreadRadius: 1,
topLeftShadowColor: Colors.white,
bottomRightShadowColor: Colors.grey.shade500,
height: 100,
width: width,
bottomRightOffset: const Offset(4, 4),
topLeftOffset: const Offset(-4, -4),
child: const Row(
children: [
Icon(Icons.opacity_rounded, size: 30),
SizedBox(width: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Drop", style: TextStyle(fontSize: 20)),
Text("Neu morphism", style: TextStyle(fontSize: 18)),
],
),
],
),
),
);
}
}
更多关于Flutter拟物化UI设计插件flutter_neumorphism_ui的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复
更多关于Flutter拟物化UI设计插件flutter_neumorphism_ui的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是如何在Flutter项目中使用flutter_neumorphism_ui
插件的详细示例代码。这个插件可以帮助你快速实现拟物化UI设计。首先,你需要确保在pubspec.yaml
文件中添加了该依赖项:
dependencies:
flutter:
sdk: flutter
flutter_neumorphism_ui: ^最新版本号 # 请替换为实际可用的最新版本号
然后运行flutter pub get
来安装依赖。
下面是一个完整的示例代码,展示了如何使用flutter_neumorphism_ui
来创建一个简单的拟物化UI界面:
import 'package:flutter/material.dart';
import 'package:flutter_neumorphism_ui/flutter_neumorphism_ui.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Neumorphism UI Example',
theme: ThemeData(
// 自定义主题,可以设置为深色或浅色主题
brightness: Brightness.dark,
),
home: NeumorphismHomePage(),
);
}
}
class NeumorphismHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Flutter Neumorphism UI'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 拟物化按钮
NeuButton(
text: 'Neu Button',
onPressed: () {
print('Button pressed!');
},
style: NeuButtonStyle.filled,
),
SizedBox(height: 16.0),
// 拟物化输入框
NeuTextField(
labelText: 'Neu TextField',
hintText: 'Enter some text',
),
SizedBox(height: 16.0),
// 拟物化卡片
NeuCard(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Neu Card', style: TextStyle(fontSize: 20)),
SizedBox(height: 8.0),
Text('This is a NeuCard component.', style: TextStyle(fontSize: 16)),
],
),
),
),
SizedBox(height: 16.0),
// 拟物化开关
NeuSwitch(
value: false,
onChanged: (value) {
print('Switch state: $value');
},
),
SizedBox(height: 16.0),
],
),
),
);
}
}
代码说明
- 依赖项:在
pubspec.yaml
中添加flutter_neumorphism_ui
依赖项。 - 主应用:
MyApp
类作为应用入口,定义了一个MaterialApp,并设置了主题。 - 主页:
NeumorphismHomePage
类定义了应用的主页面,其中包含了几个拟物化UI组件:NeuButton
:一个拟物化按钮,当点击时会打印一条消息。NeuTextField
:一个拟物化输入框,用户可以在其中输入文本。NeuCard
:一个拟物化卡片,包含一个文本标签和描述。NeuSwitch
:一个拟物化开关,可以切换其状态并打印当前状态。
通过这些示例代码,你可以快速了解如何在Flutter中使用flutter_neumorphism_ui
插件来创建拟物化UI设计。你可以根据需要进一步自定义和扩展这些组件。