Visitar URL original
[animations] OpenContainer demo and polish by goderbauer · Pull Request #79 · flutter/packages · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Open Container Card Demo
  • Loading branch information
shihaohong authored and goderbauer committed Feb 3, 2020
commit 5db570acc263820a2196d756414cc6a6ba5be919
170 changes: 170 additions & 0 deletions packages/animations/example/lib/container_transition.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

const String _loremIpsumParagraph = '''
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vulputate dignissim suspendisse in est. Ut ornare lectus sit amet. Eget nunc lobortis mattis aliquam faucibus purus in. Hendrerit gravida rutrum quisque non tellus orci ac auctor. Mattis aliquam faucibus purus in massa. Tellus rutrum tellus pellentesque eu tincidunt tortor. Nunc eget lorem dolor sed. Nulla at volutpat diam ut venenatis tellus in metus. Tellus cras adipiscing enim eu turpis. Pretium fusce id velit ut tortor. Adipiscing enim eu turpis egestas pretium. Quis varius quam quisque id. Blandit aliquam etiam erat velit scelerisque. In nisl nisi scelerisque eu. Semper risus in hendrerit gravida rutrum quisque. Suspendisse in est ante in nibh mauris cursus mattis molestie. Adipiscing elit duis tristique sollicitudin nibh sit amet commodo nulla. Pretium viverra suspendisse potenti nullam ac tortor vitae.
''';

/// The demo page for [OpenContainerTransform].
class OpenContainerTransformDemo extends StatefulWidget {
@override
_OpenContainerTransformDemoState createState() =>
_OpenContainerTransformDemoState();
}

class _OpenContainerTransformDemoState extends State<OpenContainerTransformDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Container Transform')),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: <Widget>[
_OpenContainerWrapper(
closedBuilder: (BuildContext context, VoidCallback openContainer) {
return _ExampleCard(openContainer: openContainer);
},
),
],
),
),
);
}
}

class _OpenContainerWrapper extends StatelessWidget {
const _OpenContainerWrapper({
this.closedBuilder,
});

final OpenContainerBuilder closedBuilder;

@override
Widget build(BuildContext context) {
return OpenContainer(
openBuilder: (BuildContext context, VoidCallback _) {
return _DetailsPage();
},
closedBuilder: closedBuilder,
);
}
}

class _ExampleCard extends StatelessWidget {
const _ExampleCard({this.openContainer});

final VoidCallback openContainer;

@override
Widget build(BuildContext context) {
return SizedBox(
height: 350,
child: Stack(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
child: Container(
color: Colors.black38,
child: Padding(
padding: const EdgeInsets.all(40.0),
child: Image.asset(
'assets/placeholder_image.png',
),
),
),
),
const ListTile(
title: Text('Title'),
subtitle: Text('Secondary text'),
),
Padding(
padding: const EdgeInsets.only(
left: 16.0,
right: 16.0,
bottom: 16.0,
),
child: Text(
'Lorem ipsum dolor sit amet, consectetur '
'adipiscing elit, sed do eiusmod tempor.',
style: Theme.of(context).textTheme.body1
.copyWith(color: Colors.black54),
),
),
],
),
InkWell(
splashColor: Colors.black38,
onTap: () {
Future<void>.delayed(
const Duration(milliseconds: 250),
openContainer,
);
},
),
],
),
);
}
}

class _DetailsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Container Transform')),
body: ListView(
children: <Widget>[
Container(
color: Colors.black38,
height: 250,
child: Padding(
padding: const EdgeInsets.all(70.0),
child: Image.asset(
'assets/placeholder_image.png',
),
),
),
Padding(
padding: const EdgeInsets.only(
top: 20.0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should some padding be added to the bottom as well? The bottom of the text seems awfully close to the bottom navigation bar:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

left: 20.0,
right: 20.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Title',
style: Theme.of(context).textTheme.headline
.copyWith(
color: Colors.black54,
fontSize: 30.0,
),
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 5.0),
),
Text(
_loremIpsumParagraph,
style: Theme.of(context).textTheme.body1
.copyWith(
color: Colors.black54,
height: 1.5,
fontSize: 16.0,
),
),
],
),
),
],
),
);
}
}
17 changes: 17 additions & 0 deletions packages/animations/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:animations_example/container_transition.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

Expand Down Expand Up @@ -105,6 +106,22 @@ class _TransitionsHomePageState extends State<_TransitionsHomePage> {
},
title: const Text('Slow animations'),
),
_TransitionListTile(
title: 'Container Transform',
subtitle: 'The container acts as a persistent '
'element as its dimensions, position, and '
'shape animate seamlessly during the '
'transition.',
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) {
return OpenContainerTransformDemo();
},
),
);
},
),
],
),
);
Expand Down