Skip to content

Commit

Permalink
Merge pull request #220 from shinyina/feature/result
Browse files Browse the repository at this point in the history
feat(Result结果): 新增Result结果组件
  • Loading branch information
Luozf12345 authored Aug 24, 2024
2 parents f6837f6 + b56ba0a commit 1944fff
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 2 deletions.
11 changes: 11 additions & 0 deletions tdesign-component/example/assets/api/result_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## API
### TDResult
#### 默认构造方法

| 参数 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| description | String? | - | 描述文本,用于提供额外信息 |
| icon | Widget? | - | 图标组件,用于在结果中显示一个图标 |
| titleStyle | TextStyle? | - | 自定义字体样式,用于设置标题文本的样式 |
| theme | TDResultTheme | - | 主题样式,定义了结果组件的视觉风格 |
| title | String | - | 标题文本,显示结果的主要信息 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

TDResult _buildBasicResultDefault(BuildContext context) {
return const TDResult(
title: '默认状态',
theme: TDResultTheme.defaultTheme,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

TDResult _buildBasicResultError(BuildContext context) {
return const TDResult(
title: '失败状态',
theme: TDResultTheme.error,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

TDResult _buildBasicResultSuccess(BuildContext context) {
return const TDResult(
title: '成功状态',
theme: TDResultTheme.success,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

TDResult _buildBasicResultWarning(BuildContext context) {
return const TDResult(
title: '警示状态',
theme: TDResultTheme.warning,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Widget _buildCustomResult(BuildContext context) {
return TDResult(
title: '自定义结果',
icon: Image.asset('assets/img/illustration.png'),
description: '描述文字');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

TDResult _buildResultWithDescriptionDefault(BuildContext context) {
return const TDResult(
title: '默认状态',
theme: TDResultTheme.defaultTheme,
description: '描述文字',
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

TDResult _buildResultWithDescriptionError(BuildContext context) {
return const TDResult(
title: '失败状态',
theme: TDResultTheme.error,
description: '描述文字',
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

TDResult _buildResultWithDescriptionSuccess(BuildContext context) {
return const TDResult(
title: '成功状态',
theme: TDResultTheme.success,
description: '描述文字',
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

TDResult _buildResultWithDescriptionWarning(BuildContext context) {
return const TDResult(
title: '警示状态',
theme: TDResultTheme.warning,
description: '描述文字',
);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tdesign-component/example/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import 'page/td_popup_page.dart';
import 'page/td_radio_page.dart';
import 'page/td_radius_page.dart';
import 'page/td_refresh_page.dart';
import 'page/td_result_page.dart';
import 'page/td_search_bar_page.dart';
import 'page/td_shadows_page.dart';
import 'page/td_slider_page.dart';
Expand Down Expand Up @@ -190,8 +191,7 @@ Map<String, List<ExamplePageModel>> exampleMap = {
ExamplePageModel(
text: 'Result 结果',
name: 'result',
isTodo: true,
pageBuilder: _wrapInheritedTheme((context) => const TodoPage())),
pageBuilder: _wrapInheritedTheme((context) => const TDResultPage())),
ExamplePageModel(
text: 'Skeleton 骨架屏',
name: 'skeleton',
Expand Down
206 changes: 206 additions & 0 deletions tdesign-component/example/lib/page/td_result_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../base/example_widget.dart';
import '../annotation/demo.dart';

class TDResultPage extends StatefulWidget {
const TDResultPage({Key? key}) : super(key: key);

@override
State<TDResultPage> createState() => _TDResultPageState();
}

class _TDResultPageState extends State<TDResultPage> {
@override
Widget build(BuildContext context) {
return ExamplePage(
title: 'Result 结果',
desc: '反馈结果状态。',
exampleCodeGroup: 'result',
children: [
ExampleModule(title: '组件类型', children: [
ExampleItem(
desc: '基础结果', ignoreCode: true, builder: _buildBasicResult),
ExampleItem(
desc: '带描述的结果',
ignoreCode: true,
builder: _buildResultWithDescription),
ExampleItem(
desc: '自定义结果', ignoreCode: true, builder: _buildCustomResult),
ExampleItem(
desc: '页面示例', ignoreCode: true, builder: _buildPageExample),
]),
],
);
}

Widget _buildBasicResult(BuildContext context) {
return Column(
children: [
CodeWrapper(
builder: _buildBasicResultSuccess,
),
const SizedBox(height: 48),
CodeWrapper(
builder: _buildBasicResultError,
),
const SizedBox(height: 48),
CodeWrapper(
builder: _buildBasicResultWarning,
),
const SizedBox(height: 48),
CodeWrapper(
builder: _buildBasicResultDefault,
),
],
);
}

Widget _buildResultWithDescription(BuildContext context) {
return Column(
children: [
CodeWrapper(
builder: _buildResultWithDescriptionSuccess,
),
const SizedBox(height: 48),
CodeWrapper(
builder: _buildResultWithDescriptionError,
),
const SizedBox(height: 48),
CodeWrapper(
builder: _buildResultWithDescriptionWarning,
),
const SizedBox(height: 48),
CodeWrapper(
builder: _buildResultWithDescriptionDefault,
),
],
);
}

Widget _buildCustomResult(BuildContext context) {
return CodeWrapper(
builder: _buildCustomResultContent,
);
}

Widget _buildPageExample(BuildContext context) {
return TDButton(
text: '页面示例',
theme: TDButtonTheme.primary,
size: TDButtonSize.large,
type: TDButtonType.outline,
isBlock: true,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(
title: const Text('Result 结果'),
),
body: Column(
children: [
const SizedBox(height: 48),
const TDResult(
title: '成功状态',
theme: TDResultTheme.success,
description: '描述文字',
),
const SizedBox(height: 48),
TDButton(
text: '返回',
theme: TDButtonTheme.primary,
size: TDButtonSize.large,
type: TDButtonType.outline,
isBlock: true,
onTap: () {
Navigator.pop(context);
},
),
],
),
),
),
);
},
);
}

@Demo(group: 'result')
TDResult _buildBasicResultSuccess(BuildContext context) {
return const TDResult(
title: '成功状态',
theme: TDResultTheme.success,
);
}

@Demo(group: 'result')
TDResult _buildBasicResultError(BuildContext context) {
return const TDResult(
title: '失败状态',
theme: TDResultTheme.error,
);
}

@Demo(group: 'result')
TDResult _buildBasicResultWarning(BuildContext context) {
return const TDResult(
title: '警示状态',
theme: TDResultTheme.warning,
);
}

@Demo(group: 'result')
TDResult _buildBasicResultDefault(BuildContext context) {
return const TDResult(
title: '默认状态',
theme: TDResultTheme.defaultTheme,
);
}

@Demo(group: 'result')
TDResult _buildResultWithDescriptionSuccess(BuildContext context) {
return const TDResult(
title: '成功状态',
theme: TDResultTheme.success,
description: '描述文字',
);
}

@Demo(group: 'result')
TDResult _buildResultWithDescriptionError(BuildContext context) {
return const TDResult(
title: '失败状态',
theme: TDResultTheme.error,
description: '描述文字',
);
}

@Demo(group: 'result')
TDResult _buildResultWithDescriptionWarning(BuildContext context) {
return const TDResult(
title: '警示状态',
theme: TDResultTheme.warning,
description: '描述文字',
);
}

@Demo(group: 'result')
TDResult _buildResultWithDescriptionDefault(BuildContext context) {
return const TDResult(
title: '默认状态',
theme: TDResultTheme.defaultTheme,
description: '描述文字',
);
}

@Demo(group: 'result')
TDResult _buildCustomResultContent(BuildContext context) {
return TDResult(
title: '自定义结果',
icon: Image.asset('assets/img/illustration.png'),
description: '描述文字',
);
}
}
Loading

0 comments on commit 1944fff

Please sign in to comment.