探索高效UI设计新纪元 —— TDesign Flutter组件库深度解析与推荐
import 'package:flutter/material.dart';
import 'package:td_ui/td_ui.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
theme: TdTheme.light(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('TDesign Flutter 示例'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TdButton(
theme: TdButtonType.primary,
child: Text('主按钮'),
onTap: () => print('主按钮被点击'),
),
SizedBox(height: 16),
TdButton(
theme: TdButtonType.secondary,
child: Text('次按钮'),
onTap: () => print('次按钮被点击'),
),
SizedBox(height: 16),
TdButton(
theme: TdButtonType.text,
child: Text('文本按钮'),
onTap: () => print('文本按钮被点击'),
),
],
),
),
);
}
}
这段代码演示了如何在Flutter应用中使用TDesign库中的按钮组件TdButton
。首先,我们导入了TDesign库,并在main
函数中启动了应用。MyApp
类定义了应用的根Widget,其中配置了TDesign的主题。HomePage
是应用的主页,它包含了三个TdButton
按钮,每个按钮都绑定了点击事件。这个例子简单直观地展示了如何使用TDesign Flutter组件库,并且提供了一个学习和实践的入口。
评论已关闭