Flutter UI组件库插件sunday_ui的使用
Flutter UI组件库插件sunday_ui的使用
Sunday UI 是一个为 Flutter 提供通用 UI 组件的包,支持自定义样式、Material 和 Cupertino 设计语言。它可以帮助开发者在不同平台上实现一致的外观和感觉,并且易于集成到现有的 Flutter 项目中。
特性
- 可定制的 UI 组件
- 支持 Material 和 Cupertino 设计语言
- 跨平台的一致外观和感觉
- 易于使用和集成到现有的 Flutter 项目中
- 响应式和适应性布局
开始使用
要使用此插件,只需将 sunday_ui
添加为你的 pubspec.yaml
文件中的依赖项:
dependencies:
sunday_ui: ^版本号
然后运行 flutter pub get
来获取依赖项。
示例代码
下面是一个完整的示例代码,展示了如何使用 sunday_ui
插件来创建一个简单的应用。
import 'package:color_theme_provider/color_theme_provider.dart';
import 'package:flutter/cupertino.dart';
import 'package:sunday_ui/sunday_ui.dart';
import 'package:sunday_ui_library/theme_data.dart';
void main() {
runApp(
ColorThemeProvider(
theme: LightMyTheme(),
darkTheme: DarkMyTheme(),
child: const MyApp(),
),
);
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Style _currentStyle = Style.latestIOS;
void _toggleStyle() {
setState(() {
_currentStyle = _currentStyle == Style.material ? Style.latestIOS : Style.material;
});
}
[@override](/user/override)
Widget build(BuildContext context) {
return SundayApp(
home: MyHomePage(
currentStyle: _currentStyle,
onStyleToggle: _toggleStyle,
),
title: "Style Switcher Demo",
uiStyle: _currentStyle,
);
}
}
class MyHomePage extends StatefulWidget {
final Style currentStyle;
final VoidCallback onStyleToggle;
const MyHomePage({
super.key,
required this.currentStyle,
required this.onStyleToggle,
});
[@override](/user/override)
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int currentIndex = 0;
String selectedIndex = "library";
[@override](/user/override)
Widget build(BuildContext context) {
return SundayLayout(
style: widget.currentStyle,
mobileLayoutStyle: SundayBottomBar(
items: [
SundayNavigationBarItem(
icon: const Icon(CupertinoIcons.chat_bubble_2),
label: "Messages",
style: widget.currentStyle,
),
SundayNavigationBarItem(
icon: const Icon(CupertinoIcons.gear),
label: "Settings",
style: widget.currentStyle,
),
],
currentIndex: 0,
onTap: (index) {},
style: widget.currentStyle,
tabBuilder: (BuildContext context, int index) {
return SundayScaffold(
style: widget.currentStyle,
child: Center(child: Text("Tab $index")),
);
},
),
mainView: SundayScaffold(
style: widget.currentStyle,
child: Center(child: Text("Tab $selectedIndex")),
),
desktopLayoutStyle: SideBarLayout(
title: "Title",
keyCollapsed: "desktop-sidebar-layout",
children: [
SideBarItemGroup(
isCollapsed: false,
showAndHide: false,
title: "Photo Library",
children: [
SidebarItem(
keyIndex: "library",
selectedIndex: selectedIndex,
onTap: () {
setState(() {
selectedIndex = "library";
});
},
icon: const Icon(CupertinoIcons.photo_on_rectangle),
text: "Photo Library"),
SidebarItem(
keyIndex: "liked",
selectedIndex: selectedIndex,
onTap: () {
setState(() {
selectedIndex = "liked";
});
},
icon: const Icon(CupertinoIcons.heart),
text: "Liked Photos"),
SidebarItem(
keyIndex: "recent",
selectedIndex: selectedIndex,
onTap: () {
setState(() {
selectedIndex = "recent";
});
},
icon: const Icon(CupertinoIcons.clock),
text: "Recent"),
],
),
SideBarItemGroup(
isCollapsed: false,
showAndHide: true,
title: "Albums",
children: [
SidebarItem(
keyIndex: "albums",
selectedIndex: selectedIndex,
onTap: () {
setState(() {
selectedIndex = "albums";
});
},
icon: const Icon(CupertinoIcons.square_stack),
text: "Albums"),
SidebarItem(
keyIndex: "4",
selectedIndex: selectedIndex,
onTap: () {
setState(() {
selectedIndex = "4";
});
},
icon: const Icon(CupertinoIcons.heart),
text: "Liked Photos"),
SidebarItem(
keyIndex: "5",
selectedIndex: selectedIndex,
onTap: () {
setState(() {
selectedIndex = "5";
});
},
icon: const Icon(CupertinoIcons.heart),
text: "Liked Photos"),
],
)
],
),
);
}
}
更多关于Flutter UI组件库插件sunday_ui的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter UI组件库插件sunday_ui的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是一个关于如何在Flutter项目中使用sunday_ui
组件库的示例代码案例。sunday_ui
是一个提供丰富UI组件的Flutter插件,能够帮助开发者快速构建美观的用户界面。
首先,你需要在你的pubspec.yaml
文件中添加sunday_ui
依赖:
dependencies:
flutter:
sdk: flutter
sunday_ui: ^最新版本号 # 请替换为实际的最新版本号
然后运行flutter pub get
来获取依赖包。
接下来是一个简单的示例,展示如何使用sunday_ui
中的一些组件。
import 'package:flutter/material.dart';
import 'package:sunday_ui/sunday_ui.dart'; // 导入sunday_ui
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sunday UI Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SundayUIDemo(),
);
}
}
class SundayUIDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sunday UI Demo'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 使用SundayUI的按钮组件
SundayUIButton(
text: 'Primary Button',
onPressed: () {
print('Primary Button Pressed');
},
type: SundayUIButtonType.primary,
),
SizedBox(height: 16),
// 使用SundayUI的输入框组件
SundayUITextField(
labelText: 'Enter your name',
onChanged: (value) {
print('Input value: $value');
},
),
SizedBox(height: 16),
// 使用SundayUI的卡片组件
SundayUICard(
title: 'Card Title',
content: Text('This is the content of the card.'),
leading: Icon(Icons.account_circle),
),
SizedBox(height: 16),
// 使用SundayUI的列表组件
SundayUIList.builder(
itemCount: 10,
itemBuilder: (context, index) {
return ListTile(
leading: Icon(Icons.label),
title: Text('Item $index'),
);
},
),
],
),
),
);
}
}
在这个示例中,我们展示了如何使用sunday_ui
提供的几个组件:
- SundayUIButton:一个按钮组件,可以设置按钮的类型和点击事件。
- SundayUITextField:一个输入框组件,可以监听输入内容的变化。
- SundayUICard:一个卡片组件,可以显示标题、内容和前导图标。
- SundayUIList.builder:一个列表构建器,用于动态生成列表项。
请注意,sunday_ui
的实际组件和API可能会有所不同,具体请参考其官方文档和示例代码。此外,确保你使用的是最新版本的sunday_ui
,因为库的API可能会随版本更新而变化。