keyframe 0.0.1 copy "keyframe: ^0.0.1" to clipboard
keyframe: ^0.0.1 copied to clipboard

Improve the animation experience in Flutter by transforming Tweens into Timeline with Keyframe like a video editor, but using programming language.

example/lib/main.dart

import 'dart:convert';
import 'dart:developer';

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {
  late final AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    );

    _controller.addListener(() {
      setState(() {});
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  final bool _initialized = false;

  init() {
    if (_initialized) return;
    registerExtension('ext.keyframe.up', (method, parameters) async {
      return ServiceExtensionResponse.result(
        jsonEncode({
          'index': 1,
          'value': 2,
        }),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    final timeline = Timeline(
      properties: [
        KeyframeProperty<Color>(
          [
            Keyframe<Color>(0, Colors.red),
            Keyframe<Color>(0.5, Colors.green),
            Keyframe<Color>(0.7, Colors.blue),
            Keyframe<Color>(1, Colors.red),
          ],
        ),
        KeyframeProperty<Size>(
          [
            Keyframe(0, const Size(200, 200)),
            Keyframe(0.5, const Size(300, 200)),
            Keyframe(0.7, const Size(300, 300)),
            Keyframe(1.0, const Size(200, 200)),
          ],
        ),
      ],
    ).animate(_controller);

    final color = timeline.value<Color>();
    final size = timeline.value<Size>();

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              width: size.width,
              height: size.height,
              color: color,
            ),
            const Text(
              'You have pushed the button this many times:',
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _controller.reset();
          _controller.forward();
          init();
          print(extensionStreamHasListener);
          postEvent('ext.keyframe', {
            'test': 'dsfdfd',
          });
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
3
likes
130
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

Improve the animation experience in Flutter by transforming Tweens into Timeline with Keyframe like a video editor, but using programming language.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on keyframe