Skip to content

Commit

Permalink
Merge pull request gskinnerTeam#11 from gskinnerTeam/ticket-fold-issue-5
Browse files Browse the repository at this point in the history
Ticket fold issue 5
  • Loading branch information
esDotDev authored Jan 6, 2020
2 parents 20115bb + 58afa2b commit 56577aa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
6 changes: 5 additions & 1 deletion vignettes/ticket_fold/lib/flight_barcode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class FlightBarcode extends StatelessWidget {
decoration: BoxDecoration(borderRadius: BorderRadius.circular(4.0), color: Colors.white),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 14.0),
child: Image.asset('images/barcode.png', package: App.pkg),
child: MaterialButton(
child: Image.asset('images/barcode.png', package: App.pkg),
onPressed: () {
print('Button was pressed');
}),
));
}
32 changes: 17 additions & 15 deletions vignettes/ticket_fold/lib/folding_ticket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ class FoldingTicket extends StatefulWidget {
static const double padding = 16.0;
final bool isOpen;
final List<FoldEntry> entries;
final Function onClick;
final Duration duration;

FoldingTicket({this.duration, @required this.entries, this.isOpen = false});
FoldingTicket({this.duration, @required this.entries, this.isOpen = false, this.onClick});

@override
_FoldingTicketState createState() => _FoldingTicketState();
Expand Down Expand Up @@ -36,7 +37,6 @@ class _FoldingTicketState extends State<FoldingTicket> with SingleTickerProvider
@override
void didUpdateWidget(FoldingTicket oldWidget) {
// Opens or closes the ticked if the status changed
isOpen ? _controller.forward() : _controller.reverse();
_updateFromWidget();
super.didUpdateWidget(oldWidget);
}
Expand All @@ -47,7 +47,6 @@ class _FoldingTicketState extends State<FoldingTicket> with SingleTickerProvider
super.dispose();
}


@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -61,38 +60,41 @@ class _FoldingTicketState extends State<FoldingTicket> with SingleTickerProvider
);
}

Widget _buildEntry(int index, [double offset = 0.0]) {
Widget _buildEntry(int index) {
FoldEntry entry = _entries[index];
int count = _entries.length - 1;
double ratio = max(0.0, min(1.0, _ratio * count + 1.0 - index * 1.0));

Matrix4 mtx = Matrix4.identity()
..setEntry(3, 2, 0.001)
..setEntry(1, 2, 0.2)
..translate(0.0, offset)
..rotateX(pi * (ratio - 1.0));

Widget card = SizedBox(height: entry.height, child: ratio < 0.5 ? entry.back : entry.front);

return Transform(
alignment: Alignment.topCenter,
transform: mtx,
child: Container(
// Note: Container supports a transform property, but not alignment for it.
foregroundDecoration: BoxDecoration(color: Colors.black.withOpacity((0.5 - (0.5 - ratio).abs()) * 0.5)),
child: (index == count || ratio <= 0.5)
? card
: // Don't build a stack if it isn't needed.
Stack(children: [
card,
_buildEntry(index + 1, entry.height),
]),
child: GestureDetector(
onTap: widget.onClick,
child: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
// Note: Container supports a transform property, but not alignment for it.
child: (index == count || ratio <= 0.5)
? card
: // Don't build a stack if it isn't needed.
Column(children: [
card,
_buildEntry(index + 1),
]),
),
));
}

void _updateFromWidget() {
_entries = widget.entries;
_controller.duration = widget.duration ?? Duration(milliseconds: 400 * (_entries.length - 1));
isOpen ? _controller.forward() : _controller.reverse();
}

void _tick() {
Expand Down
8 changes: 1 addition & 7 deletions vignettes/ticket_fold/lib/ticket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ class _TicketState extends State<Ticket> {

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _handleOnTap,
child: FoldingTicket(
entries: _getEntries(),
isOpen: _isOpen,
),
);
return FoldingTicket(entries: _getEntries(), isOpen: _isOpen, onClick: _handleOnTap);
}

List<FoldEntry> _getEntries() {
Expand Down
2 changes: 1 addition & 1 deletion vignettes/ticket_fold/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ packages:
shared:
dependency: "direct main"
description:
path: "..\\_shared"
path: "../_shared"
relative: true
source: path
version: "1.0.0+1"
Expand Down

0 comments on commit 56577aa

Please sign in to comment.