flutter_cached_transition 1.0.1+1 copy "flutter_cached_transition: ^1.0.1+1" to clipboard
flutter_cached_transition: ^1.0.1+1 copied to clipboard

This package provides customizable widgets that preserve widget state while applying transition animations.

example/main.dart

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

void main() {
  runApp(const RootApp());
}

class RootApp extends StatefulWidget {
  const RootApp({super.key});

  @override
  State<RootApp> createState() => _RootAppState();
}

class _RootAppState extends State<RootApp> {
  int _index = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: SafeArea(
          child: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              spacing: 15,
              children: [
                CachedTransition(
                  duration: Duration(milliseconds: 500),
                  curve: Curves.ease,
                  transitionBuilder: (
                    Widget child,
                    Animation<double> primaryAnimation,
                    Animation<double> secondaryAnimation,
                  ) {
                    return FadeTransition(
                      opacity: primaryAnimation,
                      child: child,
                    );
                  },
                  child: Counter(key: ValueKey(_index)),
                ),
                Row(
                  mainAxisSize: MainAxisSize.min,
                  spacing: 8,
                  children: [
                    FilledButton(
                      onPressed: () => setState(() => _index = 0),
                      child: Text("Move to 0"),
                    ),
                    FilledButton(
                      onPressed: () => setState(() => _index = 1),
                      child: Text("Move to 1"),
                    ),
                    FilledButton(
                      onPressed: () => setState(() => _index = 2),
                      child: Text("Move to 2"),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class Counter extends StatefulWidget {
  const Counter({super.key});

  @override
  State<Counter> createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => setState(() => count += 1),
      child: Container(
        padding: EdgeInsets.symmetric(vertical: 15, horizontal: 60),
        color: Colors.amber,
        child: Text(count.toString(), style: TextStyle(fontSize: 32)),
      ),
    );
  }
}
2
likes
155
points
1
downloads

Publisher

verified publisherttangkong.dev

Weekly Downloads

This package provides customizable widgets that preserve widget state while applying transition animations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on flutter_cached_transition