Flutter 在颤振中如何更改FAB(浮动动作按钮)自定义动画图标
我是一个新手,现在我一直在改变FAB动画。实际上,我正在尝试在按下FAB之前添加图标,在按下FAB之后关闭图标而不是添加图标。 我提供了一个动画gif文件链接,以更了解如果有人知道解决方案,请建议我解决这个问题 这里是链接 在这个链接中,提供的动画显示,按下前显示菜单选项图标,按下后显示关闭图标,但我想添加选项,而不是菜单选项 像添加\关闭而不是菜单\关闭动画图标Flutter 在颤振中如何更改FAB(浮动动作按钮)自定义动画图标,flutter,flutter-layout,flutter-animation,Flutter,Flutter Layout,Flutter Animation,我是一个新手,现在我一直在改变FAB动画。实际上,我正在尝试在按下FAB之前添加图标,在按下FAB之后关闭图标而不是添加图标。 我提供了一个动画gif文件链接,以更了解如果有人知道解决方案,请建议我解决这个问题 这里是链接 在这个链接中,提供的动画显示,按下前显示菜单选项图标,按下后显示关闭图标,但我想添加选项,而不是菜单选项 像添加\关闭而不是菜单\关闭动画图标 我希望您理解我的问题,并向我提出建议我认为此代码满足您的要求 void main() { runApp(MyApp()); }
我希望您理解我的问题,并向我提出建议我认为此代码满足您的要求
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter FAB Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text("FAB"),
),
floatingActionButton: AnimatedIconButton(
size: 30,
onPressed: () {
},
duration: Duration(milliseconds: 200),
endIcon: Icon(
Icons.close,
color: Colors.white,
),
startIcon: Icon(
Icons.add,
color: Colors.white,
),
startBackgroundColor: Colors.blue,
endBackgroundColor: Colors.blue,
),
);
}
}
我认为该代码满足您的要求
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter FAB Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text("FAB"),
),
floatingActionButton: AnimatedIconButton(
size: 30,
onPressed: () {
},
duration: Duration(milliseconds: 200),
endIcon: Icon(
Icons.close,
color: Colors.white,
),
startIcon: Icon(
Icons.add,
color: Colors.white,
),
startBackgroundColor: Colors.blue,
endBackgroundColor: Colors.blue,
),
);
}
}
此代码将适用于您的所有需求,例如动画、多个按下的fab按钮,还支持图像作为fab图标
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter FAB Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: UniWidget(),
);
}
}
class UniWidget extends StatefulWidget {
@override
_UniWidgetState createState() => _UniWidgetState();
}
class _UniWidgetState extends State<UniWidget> {
@override
Widget build(BuildContext context) {
var childButtons = List<UnicornButton>();
childButtons.add(UnicornButton(
hasLabel: false,
currentButton: FloatingActionButton(
backgroundColor: Colors.blue,
mini: false,
child: Padding(
padding: const EdgeInsets.all(15),
child: Image.asset('assets/images/arrow.png'),
),
onPressed: () {
print('scanbar');
},
)));
childButtons.add(UnicornButton(
hasLabel: false,
currentButton: FloatingActionButton(
backgroundColor: Colors.blue,
mini: false,
child: Padding(
padding: const EdgeInsets.all(15),
child: Image.asset('assets/images/contact.png'),
),
onPressed: () {
print('Contact');
},
)));
return Scaffold(
floatingActionButton: UnicornDialer(
parentButtonBackground: Colors.blue,
orientation: UnicornOrientation.VERTICAL,
childPadding: 10.0,
parentButton: Icon(Icons.add),
childButtons: childButtons),
appBar: AppBar(
title: Text("Fab demo"),
),
body: Center());
}
}
我希望它能满足您所有类型的需求,并在您的项目中很好地工作。此代码可以满足您的所有需求,例如动画、多个按下的fab按钮,以及支持图像作为fab图标
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter FAB Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: UniWidget(),
);
}
}
class UniWidget extends StatefulWidget {
@override
_UniWidgetState createState() => _UniWidgetState();
}
class _UniWidgetState extends State<UniWidget> {
@override
Widget build(BuildContext context) {
var childButtons = List<UnicornButton>();
childButtons.add(UnicornButton(
hasLabel: false,
currentButton: FloatingActionButton(
backgroundColor: Colors.blue,
mini: false,
child: Padding(
padding: const EdgeInsets.all(15),
child: Image.asset('assets/images/arrow.png'),
),
onPressed: () {
print('scanbar');
},
)));
childButtons.add(UnicornButton(
hasLabel: false,
currentButton: FloatingActionButton(
backgroundColor: Colors.blue,
mini: false,
child: Padding(
padding: const EdgeInsets.all(15),
child: Image.asset('assets/images/contact.png'),
),
onPressed: () {
print('Contact');
},
)));
return Scaffold(
floatingActionButton: UnicornDialer(
parentButtonBackground: Colors.blue,
orientation: UnicornOrientation.VERTICAL,
childPadding: 10.0,
parentButton: Icon(Icons.add),
childButtons: childButtons),
appBar: AppBar(
title: Text("Fab demo"),
),
body: Center());
}
}
我希望它能满足您所有类型的需求,并在您的项目中运行良好。您是否尝试过自己编写代码?如果是,你用了多少代码?是的,我试过了,但没有成功。这就是为什么我分享我的问题。在GitHub上发现这段代码,它不是你想要的,但是测试它并检查动画是否足够接近。无法在我自己的电脑上检查:(你尝试过自己编写代码吗?如果是,你编写了多少代码?是的,我尝试过,但没有成功。这就是我分享问题的原因在GitHub上发现此代码,它不完全是你想要的,但测试它并检查动画是否足够接近。无法在我自己的电脑上检查它:(非常感谢KK R它的工作很好,现在我想在我按下fab按钮时添加儿童多重浮动动作按钮,如果你不介意的话,你能建议我吗?我想每次我们在小事情上帮不了你的时候,你都必须在发展中多做练习。我会作为一个哥哥给出这个建议,别误会我好的。非常感谢你KKR很好,现在我想在按下fab按钮时添加儿童多重浮动动作按钮。如果你不介意的话,你可以建议我吗?我想每次我们在小事情上帮不了你的时候,你都必须在发展中进行更多的练习。我会给出这个建议,作为一个哥哥,不要误会我好的。再次感谢KK R。再次感谢你谢谢你,KKR。