我创建了一个包含 3 个状态动画的 .riv 文件:开始、处理、结束,它们位于“状态机”中。Rive 团队最近宣布了一项具有动态变化动画的新功能,它就是“状态机”。不确定如何在flutter项目中使用它,即如何动态改变动画的值。如果有人需要一些代码,没问题,我可以提供。此外,链接到 rive 的“状态机” https://www.youtube.com/watch?v=0ihqZANziCk。我没有找到与此新功能相关的任何示例。请帮忙!谢谢。
如何更改显示日期的格式?
我在这里找不到日期格式字段。这是我的示例代码:
_onDateChanging(BuildContext context, DateKind dateKind,
FlightSearchQueryProvider searchProvider) {
...
showDatePicker(
context: context,
initialDate: DateTime.tryParse(date),
firstDate: DateTime.now(),
lastDate: DateTime(2050),
helpText: helperText,
cancelText: cancelText,
confirmText: confirmText,
fieldHintText: hintText,
errorFormatText: getTranslation(context, 'invalid_date_value'),
errorInvalidText: getTranslation(context, 'invalid_date_value'),
).then((value) {
if (value != null) {
if (dateKind == DateKind.Departure) {
searchProvider.updateDepartureDate(value.toString());
} else {
searchProvider.updateArrivalDate(value.toString());
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在寻找一种在 Flutter 中结合重复和不重复动画的方法。例如,开始打开动画(不重复),然后显示一些重复的动画,例如弹跳动画。目前,我在一个小部件上方使用了 2 个动画控制器和 2 个动画构建器。这是我的示例代码:
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _outerAnimationController, //starting animation, not repetitive
builder: (context, _) {
return AnimatedBuilder(
animation: _innerCurvedAnimation, //repetitive animation, bouncing
builder: (context, _) {
return CustomPaint(
size: Size(MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height),
painter: ShowCasePainter(
centerPosition: Offset(
MediaQuery.of(context).size.width / 2,
MediaQuery.of(context).size.height / 2),
innerCircleRadius: widget.innerCircleRadius +
(_innerCurvedAnimation.value * PaddingSmall), //repetitive animation value, bouncing
outerCircleRadius: _outerAnimationTween.value, //starting animation value, not repetitive
),
);
});
});
}
Run Code Online (Sandbox Code Playgroud)
以这种方式使用多个控制器是一个好习惯吗?如何从代表不同动画的两个控制器影响animatedBuilder?
感谢您的帮助!
问题是我想从这个:{“cost”:0}解析为双倍。所以我现在拥有的是:
完整代码:
factory ShippingMethod.fromJson(Map<String, dynamic> json) {
dynamic cost = json['cost'];
print(cost.runtimeType); // printing runtime type and I get it twice!
return ShippingMethod(
code: json['code'],
title: json['title'],
description: json['description'],
cost: cost.toDouble(),
taxClassId: json['tax_class_id'],
);
}
Run Code Online (Sandbox Code Playgroud)
并打印:
I/flutter ( 480): int // first it gives me int
I/flutter ( 480): String // second it gives me String
E/flutter ( 480): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Class 'String' has no instance method 'toDouble'.
E/flutter ( 480): Receiver: "0"
E/flutter ( …Run Code Online (Sandbox Code Playgroud) 我需要删除或更改该渐变底线的颜色并删除底部导航栏的边距。在android中显示布局没有任何问题。如何解决?这是我的代码:
Widget _buildContent(BuildContext context) {
return WillPopScope(
onWillPop: () async {
bool handle = !await widget._screenStates[_pressedPosition].currentState
.maybePop();
if (handle) {
return await _showExitDialog(context);
} else {
return handle;
}
},
child: SafeArea(
child: Stack(
fit: StackFit.expand,
children: <Widget>[
PageView(
physics: new NeverScrollableScrollPhysics(),
controller: _pageController,
children: _mainScreens(),
),
Align(
alignment: Alignment.bottomCenter,
child: CurvedNavigationBar(
animationDuration: Duration(milliseconds: 200),
backgroundColor: Colors.transparent,
onTap: (int position) {
_bottomTapped(position);
},
height: BottomAppBarHeight,
items: <Widget>[
ImageIcon(
AssetImage('assets/images/logo_small.png'),
color: PrimaryColor,
size: 40.0,
),
Icon(
Icons.list,
size: 25.0,
color: (_pressedPosition …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一些带有增量和减量按钮的计数器小部件以及它们之间的计数。是否可以用设计创建计数器:
这是我现在所拥有的:
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.zero,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_createIncrementDicrementButton(Icons.remove, () => _dicrement()),
Text(_currentCount.toString()),
_createIncrementDicrementButton(Icons.add, () => _increment()),
],
),
);
}
void _increment() {
setState(() {
_currentCount++;
_counterCallback(_currentCount);
});
}
void _dicrement() {
setState(() {
if (_currentCount > 1) {
_currentCount--;
_counterCallback(_currentCount);
}
});
}
Widget _createIncrementDicrementButton(IconData icon, Function onPressed) {
return RawMaterialButton(
materialTapTargetSize: MaterialTapTargetSize.padded,
constraints: BoxConstraints(minWidth: 24.0, minHeight: 24.0),
onPressed: onPressed,
elevation: 2.0,
fillColor: LightGreyColor,
child: Icon(
icon,
color: BlackColor, …Run Code Online (Sandbox Code Playgroud)