gpt4 book ai didi

Flutter Container transform(动画包)

转载 作者:行者123 更新时间:2023-12-02 16:28:04 28 4
gpt4 key购买 nike

当我随机看到 flutter 包和库时,我发现了 animations package flutter 和我看到的,有一个我非常有用的动画,比如 android Gmail 应用程序,它有搜索导航动画。明白我的意思你可以看看this link , 数字 4 动画

我在 github 的存储库中查看了这个包的源文件夹,但是我找不到这个动画的示例实现,我不确定是否有示例代码,有没有人帮助我如何使用 Container将转换成那个?

最佳答案

动画包提供OpenContainer小部件。

这个小部件有 2 个构建器:openBuilder closedBuilder
ClosedBuilder 返回用户在打开小部件之前和关闭小部件之后看到的小部件,在流式示例中它是 SearchBar
OpenBuilder 返回用户打开关闭的小部件后显示的页面,在本示例中为 SearchPage

打开和关闭操作通过调用回调触发:openContainercloseContainer

enter image description here

import 'package:animations/animations.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
brightness: Brightness.light,
primarySwatch: Colors.blue,
scaffoldBackgroundColor: Colors.white,
),
home: MyHomePage(),
);
}
}

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

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
String searchString;

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: OpenContainer<String>(
openBuilder: (_, closeContainer) => SearchPage(closeContainer),
onClosed: (res) => setState(() {
searchString = res;
}),
tappable: false,
closedBuilder: (_, openContainer) => SearchBar(
searchString: searchString,
openContainer: openContainer,
),
),
),
),
);
}
}

class SearchBar extends StatelessWidget {
const SearchBar(
{Key key, @required this.searchString, @required this.openContainer})
: super(key: key);

final String searchString;
final VoidCallback openContainer;
@override
Widget build(BuildContext context) {
return Material(
elevation: 3,
borderRadius: BorderRadius.circular(5),
child: InkWell(
onTap: openContainer,
child: Container(
padding: EdgeInsets.all(10),
color: Colors.white,
child: Row(
children: [
Icon(Icons.search),
SizedBox(width: 10),
searchString != null
? Expanded(child: Text(searchString))
: Spacer(),
Icon(Icons.mic),
],
),
),
),
);
}
}

class SearchPage extends StatelessWidget {
const SearchPage(
this.onClose, {
Key key,
}) : super(key: key);

final void Function({String returnValue}) onClose;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
offset: Offset(0, 2),
spreadRadius: 0,
blurRadius: 1,
color: Colors.black26,
)
],
color: Colors.white,
),
child: Row(
children: [
IconButton(
icon: Icon(Icons.arrow_back),
onPressed: onClose,
),
Spacer(),
Icon(Icons.mic),
],
),
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
OutlineButton(
onPressed: () => onClose(returnValue: 'Flutter'),
child: Text('Search: "Flutter"'),
),
OutlineButton(
onPressed: () => onClose(returnValue: 'Rabbit'),
child: Text('Search: "Rabbit"'),
),
OutlineButton(
onPressed: () => onClose(returnValue: 'What is the Matrix'),
child: Text('Search: "What is the Matrix"'),
),
],
),
),
],
),
),
);
}
}

关于Flutter Container transform(动画包),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64002753/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com