Skip to content

Commit

Permalink
Merge pull request #64 from Tencent/develop
Browse files Browse the repository at this point in the history
修复TDButton无法获取自定义主题颜色的问题
  • Loading branch information
Luozf12345 authored Mar 19, 2024
2 parents d11dc18 + c55bab7 commit ff5834d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions tdesign-component/example/lib/main_run.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:tdesign_flutter/src/util/log.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'base/example_base.dart';
Expand Down Expand Up @@ -376,6 +377,7 @@ List<ExamplePageModel> sideBarExamplePage = [
];

void main() {
Log.setCustomLogPrinter((level, tag, msg) => print('[$level] $tag ==> $msg'));
runApp(const MyApp());

SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
Expand Down
4 changes: 4 additions & 0 deletions tdesign-component/example/lib/page/td_theme_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ class TestWidget extends StatelessWidget {
textColor:
TDTheme.of(context).successNormalColor, // 明确使用内层主题,必须传context
),
const TDButton(
text: '使用内层赋值主题',
theme: TDButtonTheme.primary,
),
TDText(
'使用默认主题',
font:
Expand Down
10 changes: 3 additions & 7 deletions tdesign-component/lib/src/components/button/td_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,21 @@ class _TDButtonState extends State<TDButton> {
TDButtonStyle? _innerDisableStyle;
double? _width;
double? _height;
EdgeInsetsGeometry? _padding;
EdgeInsetsGeometry? _margin;
Alignment? _alignment;
Font? _textFont;
TextStyle? _textStyle;
double? _iconSize;

_updateParams(){
_updateParams() async {
_buttonStatus = widget.disabled ? TDButtonStatus.disable : TDButtonStatus.defaultState;
_innerDefaultStyle = widget.style ?? _innerDefaultStyle;
_innerActiveStyle = widget.activeStyle ?? _innerActiveStyle;
_innerDisableStyle = widget.disableStyle ?? _innerDisableStyle;
_width = _getWidth();
_height = _getHeight();
_padding = _getPadding();
_margin = _getMargin();
_alignment = widget.shape == TDButtonShape.filled || widget.isBlock ? Alignment.center : null;
if (widget.text != null) {
_textFont = _getTextFont();
_textStyle = widget.disabled ? widget.disableTextStyle : widget.textStyle;
}
if(widget.icon != null){
Expand Down Expand Up @@ -165,7 +161,7 @@ class _TDButtonState extends State<TDButton> {
width: _width,
height: _height,
alignment: _alignment,
padding: _padding,
padding: _getPadding(),
margin: _margin,
decoration: BoxDecoration(
color: style.backgroundColor,
Expand Down Expand Up @@ -234,7 +230,7 @@ class _TDButtonState extends State<TDButton> {
if (widget.text != null) {
var text = TDText(
widget.text!,
font: _textFont,
font: _getTextFont(),
textColor:
style.textColor ?? TDTheme.of(context).fontGyColor1,
style: _textStyle,
Expand Down
1 change: 1 addition & 0 deletions tdesign-component/lib/src/theme/td_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class TDTheme extends StatelessWidget {
var data = Theme.of(context).extensions[TDThemeData] as TDThemeData?;
return data ?? TDThemeData.defaultData();
} catch (e) {
Log.w('TDTheme', 'TDTheme.of() error: $e');
return TDThemeData.defaultData();
}
}
Expand Down

0 comments on commit ff5834d

Please sign in to comment.