1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6
7/// Flutter code sample for [AnimatedSlide].
8
9void main() => runApp(const AnimatedSlideApp());
10
11class AnimatedSlideApp extends StatelessWidget {
12 const AnimatedSlideApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return const MaterialApp(home: AnimatedSlideExample());
17 }
18}
19
20class AnimatedSlideExample extends StatefulWidget {
21 const AnimatedSlideExample({super.key});
22
23 @override
24 State<AnimatedSlideExample> createState() => _AnimatedSlideExampleState();
25}
26
27class _AnimatedSlideExampleState extends State<AnimatedSlideExample> {
28 Offset offset = Offset.zero;
29
30 @override
31 Widget build(BuildContext context) {
32 final TextTheme textTheme = Theme.of(context).textTheme;
33
34 return Scaffold(
35 appBar: AppBar(title: const Text('AnimatedSlide Sample')),
36 body: Padding(
37 padding: const EdgeInsets.all(16.0),
38 child: Column(
39 mainAxisSize: MainAxisSize.min,
40 children: <Widget>[
41 Expanded(
42 child: Row(
43 children: <Widget>[
44 Expanded(
45 child: Container(
46 alignment: Alignment.center,
47 padding: const EdgeInsets.all(50.0),
48 child: AnimatedSlide(
49 offset: offset,
50 duration: const Duration(milliseconds: 500),
51 curve: Curves.easeInOut,
52 child: const FlutterLogo(size: 50.0),
53 ),
54 ),
55 ),
56 Column(
57 children: <Widget>[
58 Text('Y', style: textTheme.bodyMedium),
59 Expanded(
60 child: RotatedBox(
61 quarterTurns: 1,
62 child: Slider(
63 min: -5.0,
64 max: 5.0,
65 value: offset.dy,
66 onChanged: (double value) {
67 setState(() {
68 offset = Offset(offset.dx, value);
69 });
70 },
71 ),
72 ),
73 ),
74 ],
75 ),
76 ],
77 ),
78 ),
79 Row(
80 mainAxisAlignment: MainAxisAlignment.spaceEvenly,
81 children: <Widget>[
82 Text('X', style: textTheme.bodyMedium),
83 Expanded(
84 child: Slider(
85 min: -5.0,
86 max: 5.0,
87 value: offset.dx,
88 onChanged: (double value) {
89 setState(() {
90 offset = Offset(value, offset.dy);
91 });
92 },
93 ),
94 ),
95 const SizedBox(width: 48.0),
96 ],
97 ),
98 ],
99 ),
100 ),
101 );
102 }
103}
104

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com