Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rate #338

Merged
merged 9 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,7 @@ class IntlResourceDelegate extends TDResourceDelegate {

@override
String get end => AppLocalizations.of(context)!.end;

@override
String get notRated => AppLocalizations.of(context)!.notRated;
}
3 changes: 2 additions & 1 deletion tdesign-component/example/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import 'page/td_picker_page.dart';
import 'page/td_popup_page.dart';
import 'page/td_radio_page.dart';
import 'page/td_radius_page.dart';
import 'page/td_rate_page.dart';
import 'page/td_refresh_page.dart';
import 'page/td_search_bar_page.dart';
import 'page/td_shadows_page.dart';
Expand Down Expand Up @@ -127,7 +128,7 @@ Map<String, List<ExamplePageModel>> exampleMap = {
ExamplePageModel(
text: 'Radio 单选框', name: 'radio', pageBuilder: _wrapInheritedTheme((context) => const TDRadioPage())),
ExamplePageModel(
text: 'Rate 评分', name: 'rate', isTodo: true, pageBuilder: _wrapInheritedTheme((context) => const TodoPage())),
text: 'Rate 评分', name: 'rate', pageBuilder: _wrapInheritedTheme((context) => const TDRatePage())),
ExamplePageModel(
text: 'Search 搜索框', name: 'search', pageBuilder: _wrapInheritedTheme((context) => const TDSearchBarPage())),
ExamplePageModel(
Expand Down
3 changes: 2 additions & 1 deletion tdesign-component/example/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"december": "December",
"time": "Time",
"start": "Start",
"end": "End"
"end": "End",
"notRated": "Not rated"
}
3 changes: 2 additions & 1 deletion tdesign-component/example/lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"december": "12 月",
"time": "时间",
"start": "开始",
"end": "结束"
"end": "结束",
"notRated": "未评分"
}
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ TDDropdownMenu _buildOverflow(BuildContext context) {
tabBarWidth: 200,
tabBarAlign: MainAxisAlignment.start,
options: [
TDDropdownItemOption(label: '选项1', value: '1', selected: true),
TDDropdownItemOption(label: '选项1选项1选项1选项1选项1选项1选项1', value: '1', selected: true),
TDDropdownItemOption(label: '选项2', value: '2'),
],
),
Expand Down
161 changes: 161 additions & 0 deletions tdesign-component/example/lib/page/td_rate_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import '../annotation/demo.dart';
import '../base/example_widget.dart';

///
/// TDRadio演示
///
class TDRatePage extends StatefulWidget {
const TDRatePage({Key? key}) : super(key: key);

@override
State<StatefulWidget> createState() {
return TDRatePageState();
}
}

class TDRatePageState extends State<TDRatePage> {
@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return ExamplePage(
title: tdTitle(),
desc: '用于对某行为/事物进行打分。',
exampleCodeGroup: 'rate',
backgroundColor: TDTheme.of(context).grayColor2,
children: [
ExampleModule(title: '组件类型', children: [
ExampleItem(desc: '实心评分', builder: _buildFilledRate),
ExampleItem(desc: '自定义评分', builder: _buildCusRate),
ExampleItem(desc: '自定义评分数量', builder: _buildNumRate),
ExampleItem(desc: '带描述评分', builder: _buildMsgRate),
ExampleItem(desc: '评分弹框位置', builder: _buildDRate),
]),
ExampleModule(title: '组件状态', children: [
ExampleItem(desc: '只可选全星时', builder: _buildFullRate),
ExampleItem(desc: '可选半星时', builder: _buildHalfRate),
]),
ExampleModule(title: '组件样式', children: [
ExampleItem(desc: '评分大小', builder: _buildSizeRate),
ExampleItem(desc: '设置评分颜色', builder: _buildColorRate),
]),
ExampleModule(title: '特殊样式', children: [
ExampleItem(desc: '竖向带描述评分', builder: _buildOtherRate),
]),
]);
}

@Demo(group: 'rate')
Widget _buildFilledRate(BuildContext context) {
return const TDCell(title: '实心评分', noteWidget: TDRate(value: 3));
}

@Demo(group: 'rate')
Widget _buildCusRate(BuildContext context) {
return const TDCell(title: '自定义评分', noteWidget: TDRate(value: 3, icon: [TDIcons.thumb_up]));
}

@Demo(group: 'rate')
Widget _buildNumRate(BuildContext context) {
return const TDCell(
title: '自定义评分数量',
noteWidget: TDRate(
value: 2,
count: 3,
));
}

@Demo(group: 'rate')
Widget _buildMsgRate(BuildContext context) {
return Column(children: const [
TDCell(title: '带描述评分', noteWidget: TDRate(value: 3, showText: true, texts: ['1分', '2分', '3分', '4分', '5分'])),
SizedBox(height: 16),
TDCell(title: '带描述评分', noteWidget: TDRate(value: 3, showText: true))
]);
}

@Demo(group: 'rate')
Widget _buildDRate(BuildContext context) {
return Column(children: const [
TDCell(title: '顶部显示', noteWidget: TDRate(placement: PlacementEnum.top)),
SizedBox(height: 16),
TDCell(title: '不显示', noteWidget: TDRate(placement: PlacementEnum.none)),
SizedBox(height: 16),
TDCell(title: '底部显示', noteWidget: TDRate(placement: PlacementEnum.bottom)),
]);
}

@Demo(group: 'rate')
Widget _buildFullRate(BuildContext context) {
return const TDCell(title: '点击活滑动', noteWidget: TDRate(value: 3));
}

@Demo(group: 'rate')
Widget _buildHalfRate(BuildContext context) {
return const TDCell(title: '点击活滑动', noteWidget: TDRate(value: 3, allowHalf: true));
}

@Demo(group: 'rate')
Widget _buildSizeRate(BuildContext context) {
return Column(children: const [
TDCell(title: '默认尺寸24', noteWidget: TDRate(value: 3)),
SizedBox(height: 16),
TDCell(title: '小尺寸20', noteWidget: TDRate(value: 3, size: 20)),
]);
}

@Demo(group: 'rate')
Widget _buildColorRate(BuildContext context) {
return Column(children: const [
TDCell(
title: '填充评分',
noteWidget: TDRate(
value: 2.5,
allowHalf: true,
color: [Color(0xFFFFC51C), Color(0xFFE8E8E8)],
)),
SizedBox(height: 16),
TDCell(title: '线描评分', noteWidget: TDRate(value: 2.5, allowHalf: true, color: [Color(0xFF00A870)])),
]);
}

@Demo(group: 'rate')
Widget _buildOtherRate(BuildContext context) {
var texts = ['非常糟糕', '有些糟糕', '可以尝试', '可以前往', '推荐前往'];
return Container(
width: double.infinity,
child: Center(
child: TDRate(
value: 2,
size: 30,
showText: true,
// texts: ['非常糟糕', '有些糟糕', '可以尝试', '可以前往', '推荐前往'],
direction: Axis.vertical,
// mainAxisAlignment: MainAxisAlignment.center,
// textWidth: 64,
builderText: (context, value) {
return value == 0
? const SizedBox.shrink()
: Padding(
padding: EdgeInsets.only(top: TDTheme.of(context).spacer8),
child: TDText(
texts[(value - 1).toInt()],
font: TDTheme.of(context).fontTitleMedium,
textColor: TDTheme.of(context).warningColor5,
),
);
},
),
),

padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
color: Colors.white,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TDDropdownItem<T> extends StatefulWidget {
this.maxHeight,
this.tabBarWidth,
this.tabBarAlign,
this.tabBarFlex = 1,
}) : super(key: key);

/// 是否禁用
Expand Down Expand Up @@ -90,6 +91,9 @@ class TDDropdownItem<T> extends StatefulWidget {
/// [label]和[arrowIcon]/[TDDropdownMenu.arrowIcon]的对齐方式
final MainAxisAlignment? tabBarAlign;

/// 该item在menu上的宽度占比,仅在[TDDropdownMenu.isScrollable]为false时有效
final int? tabBarFlex;

static const double operateHeight = 73;

double? get minContentHeight =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class _TDDropdownMenuState extends State<TDDropdownMenu> with TickerProviderStat
_items?.length ?? 0,
(index) {
return Expanded(
flex: _items![index].tabBarFlex ?? 1,
child: _tabBarContent(index),
);
},
Expand Down Expand Up @@ -196,8 +197,9 @@ class _TDDropdownMenuState extends State<TDDropdownMenu> with TickerProviderStat
_isOpened[index] ? await Navigator.maybePop(context) : _openMenu(index);
},
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: _items![index].tabBarAlign ?? widget.tabBarAlign ?? MainAxisAlignment.center,
children: [_getText(index), _getIcon(index)],
children: [Flexible(child: _getText(index)), _getIcon(index)],
),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
Expand Down Expand Up @@ -40,6 +42,7 @@ class TDIndexesList extends StatefulWidget {
class _TDIndexesListState extends State<TDIndexesList> {
late Map<String, GlobalKey> _containerKeys;
final _indexSize = 20.0;
Timer? _hideTipTimer;
var _showTip = false;

@override
Expand All @@ -56,6 +59,12 @@ class _TDIndexesListState extends State<TDIndexesList> {
}
}

@override
void dispose() {
_hideTipTimer?.cancel();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Positioned(
Expand Down Expand Up @@ -176,7 +185,8 @@ class _TDIndexesListState extends State<TDIndexesList> {
}

void _hideTip() {
Future.delayed(
_hideTipTimer?.cancel();
_hideTipTimer = Timer(
const Duration(seconds: 1),
() {
setState(() {
Expand Down
Loading