"Fossies" - the Fresh Open Source Software Archive

Member "flutter-3.7.1/examples/api/lib/widgets/transitions/align_transition.0.dart" (1 Feb 2023, 1861 Bytes) of package /linux/misc/flutter-3.7.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "align_transition.0.dart": 3.3.10_vs_3.7.0.

    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 
    5 /// Flutter code sample for [AlignTransition].
    6 
    7 import 'package:flutter/material.dart';
    8 
    9 void main() => runApp(const MyApp());
   10 
   11 class MyApp extends StatelessWidget {
   12   const MyApp({super.key});
   13 
   14   static const String _title = 'Flutter Code Sample';
   15 
   16   @override
   17   Widget build(BuildContext context) {
   18     return const MaterialApp(
   19       title: _title,
   20       home: MyStatefulWidget(),
   21     );
   22   }
   23 }
   24 
   25 class MyStatefulWidget extends StatefulWidget {
   26   const MyStatefulWidget({super.key});
   27 
   28   @override
   29   State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
   30 }
   31 
   32 /// [AnimationController]s can be created with `vsync: this` because of
   33 /// [TickerProviderStateMixin].
   34 class _MyStatefulWidgetState extends State<MyStatefulWidget>
   35     with TickerProviderStateMixin {
   36   // Using `late final` for lazy initialization. See
   37   // https://dart.dev/null-safety/understanding-null-safety#lazy-initialization.
   38   late final AnimationController _controller = AnimationController(
   39     duration: const Duration(seconds: 2),
   40     vsync: this,
   41   )..repeat(reverse: true);
   42   late final Animation<AlignmentGeometry> _animation = Tween<AlignmentGeometry>(
   43     begin: Alignment.bottomLeft,
   44     end: Alignment.center,
   45   ).animate(
   46     CurvedAnimation(
   47       parent: _controller,
   48       curve: Curves.decelerate,
   49     ),
   50   );
   51 
   52   @override
   53   void dispose() {
   54     _controller.dispose();
   55     super.dispose();
   56   }
   57 
   58   @override
   59   Widget build(BuildContext context) {
   60     return Container(
   61       color: Colors.white,
   62       child: AlignTransition(
   63         alignment: _animation,
   64         child: const Padding(
   65           padding: EdgeInsets.all(8),
   66           child: FlutterLogo(size: 150.0),
   67         ),
   68       ),
   69     );
   70   }
   71 }