render 0.0.7 copy "render: ^0.0.7" to clipboard
render: ^0.0.7 copied to clipboard

A package to render any native static and moving flutter widgets to exportable formats

example/lib/main.dart

import 'package:example/animated_example_widget.dart';
import 'package:example/animated_example_buttons.dart';
import 'package:flutter/material.dart';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:render/render.dart';
import 'animated_example_controller.dart';
import 'animated_example_popup.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 const MaterialApp(
      home: MyHomePage(),
    );
  }
}

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

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

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  late final Future<ExampleAnimationController> init;
  final RenderController renderController =
      RenderController(logLevel: LogLevel.debug);

  @override
  void initState() {
    init = ExampleAnimationController.create(this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    init.then((value) => print("done"));
    return Scaffold(
      appBar: AppBar(
        title: const Text("Render Example"),
      ),
      body: FutureBuilder(
        future: init,
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return const Center(child: CircularProgressIndicator());
          } else if (snapshot.connectionState == ConnectionState.done &&
              snapshot.hasData) {
            final functionController = snapshot.data!;
            return Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  const Spacer(),
                  Render(
                    controller: renderController,
                    child: AnimatedExampleWidget(
                      exampleAnimationController: functionController,
                    ),
                  ),
                  const Spacer(),
                  NavigationButtons(
                    motionRenderCallback: () async {
                      functionController.play();
                      final stream = renderController.captureMotionWithStream(
                        functionController.duration,
                        settings: const MotionSettings(pixelRatio: 3),
                        format: MovFormat(audio: [
                          RenderAudio.url(
                            Uri.parse(
                                "https://www.fluttercampus.com/video.mp4"),
                          ),
                        ]),
                      );
                      setState(() {
                        functionController.attach(stream);
                      });
                      final result = await stream
                          .firstWhere((element) => element.isResult);
                      displayResult(result as RenderResult);
                    },
                    exampleAnimationController: functionController,
                    imageRenderCallback: () async {
                      final imageResult = await renderController.captureImage(
                        format: ImageFormat.png,
                        settings: const ImageSettings(pixelRatio: 3),
                      );
                      displayResult(imageResult);
                    },
                  ),
                ],
              ),
            );
          } else {
            return Center(
              child: Text(
                "Error loading: ${snapshot.error}",
                style: const TextStyle(
                  color: Colors.red,
                ),
              ),
            );
          }
        },
      ),
    );
  }

  Future<void> displayResult(RenderResult result,
      [bool saveToGallery = false]) async {
    print("file exits: ${await result.output.exists()}");
    if (mounted) {
      showDialog(
        context: context,
        builder: (BuildContext context) => AnimatedExamplePopUp(
          context: context,
          result: result,
        ),
      );
    }
    if (saveToGallery) {
      GallerySaver.saveImage(result.output.path)
          .then((value) => print("saved export to gallery"));
    }
  }
}
85
likes
0
points
140
downloads

Publisher

unverified uploader

Weekly Downloads

A package to render any native static and moving flutter widgets to exportable formats

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

ffmpeg_kit_flutter_https_gpl, flutter, path_provider, provider, rich_console, uuid

More

Packages that depend on render