mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
* add basics * web: update dependencies * TransferableTypeData added (#116) * Updating index with new samples (#121) * use arrow functions * remove newline * use verbs: random*() -> generate*() * remove <Widget>[] type annotation on lists * use raised button * _route() => _createRoute() * add parameter names to pageBuilder * use the text theme's display1 for large text * dispose animation controllers before calling super() * remove local var * use raised buttons instead of material buttons * web: updated dependencies * Added new test scripts (#122) * add carousel, card_swipe, and focus_image samples (#119) * add carousel, card_swipe, and focus_image samples * fix image assets * fix more asset images * add repeating animation * fix import * add copyright headers * remove Center widget * imageAssetName * use ClipRect, refactor _SwipeableCardState * use offset.zero * add comments * remove reference to coverflow package * change spread to toList() * refactor coverflow sample don't set width and height use const data -> images * return widget directly, fix formatting * inline transitionsBuilder * image -> imageAssetName * _rectTween() => _createTween() * _expandToPageRoute -> _createRoute * move non-updating widgets out of AnimatedBuilder * code review updates to animations demos
90 lines
2.5 KiB
Dart
90 lines
2.5 KiB
Dart
// Copyright 2019 The Flutter team. 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';
|
|
|
|
class ExpandCardDemo extends StatelessWidget {
|
|
static const String routeName = '/misc/expand_card';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(),
|
|
body: Center(
|
|
child: ExpandCard(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ExpandCard extends StatefulWidget {
|
|
_ExpandCardState createState() => _ExpandCardState();
|
|
}
|
|
|
|
class _ExpandCardState extends State<ExpandCard>
|
|
with SingleTickerProviderStateMixin {
|
|
static const Duration duration = Duration(milliseconds: 300);
|
|
bool selected = false;
|
|
|
|
double get size => selected ? 256 : 128;
|
|
|
|
void toggleExpanded() {
|
|
setState(() {
|
|
selected = !selected;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(context) {
|
|
return GestureDetector(
|
|
onTap: () => toggleExpanded(),
|
|
child: Card(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: AnimatedContainer(
|
|
duration: duration,
|
|
width: size,
|
|
height: size,
|
|
curve: Curves.ease,
|
|
child: AnimatedCrossFade(
|
|
duration: duration,
|
|
firstCurve: Curves.easeInOutCubic,
|
|
secondCurve: Curves.easeInOutCubic,
|
|
crossFadeState: selected
|
|
? CrossFadeState.showSecond
|
|
: CrossFadeState.showFirst,
|
|
// Use Positioned.fill() to pass the constraints to its children.
|
|
// This allows the Images to use BoxFit.cover to cover the correct
|
|
// size
|
|
layoutBuilder:
|
|
(topChild, topChildKey, bottomChild, bottomChildKey) {
|
|
return Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
key: bottomChildKey,
|
|
child: bottomChild,
|
|
),
|
|
Positioned.fill(
|
|
key: topChildKey,
|
|
child: topChild,
|
|
),
|
|
],
|
|
);
|
|
},
|
|
firstChild: Image.asset(
|
|
'assets/eat_cape_town_sm.jpg',
|
|
fit: BoxFit.cover,
|
|
),
|
|
secondChild: Image.asset(
|
|
'assets/eat_new_orleans_sm.jpg',
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|