widget_recorder 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

Widget Recorder for Flutter #

pub package

A Flutter package to create images from a Widget.

Usage #

  • Import the package:
import 'package:widget_recorder/widget_recorder.dart';
  • Use it:
...
WidgetRecorder(
    child: myWidget,
    controller: WidgetRecorderPeriodicController(),
    onSnapshotTaken: (WidgetRecorderSnapshot snapshot) {
        Uint8List bytes = snapshot.byteData.buffer.asUint8List();
        Image image = Image.memory(bytes);

        setState((){
            _myImage = image;
        });
    }
),
...
  • Examples:

Individual screenshots:

screenshots_example

Recording:

recording_example

[0.3.0] #

  • Breaking change: modify WidgetRecorderPeriodicController API.
  • Format code.
  • Update package description.

[0.2.0] #

  • Breaking change: remove Stream from WidgetRecorderPeriodicController.
  • Add onSnapshotTaken callback directly in the WidgetRecorder params.

[0.1.0+1] #

  • Update README.

[0.1.0] #

  • Breaking change: use controllers to get the image snapshot.

[0.0.1+1] #

  • Add example.

[0.0.1] #

  • Initial release.

example/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:simple_animations/simple_animations/controlled_animation.dart';
import 'package:widget_recorder/widget_recorder.dart';

const Size box_size = Size(180.0, 180.0);

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: TestRoute(),
    );
  }
}

class TestRoute extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _TestRouteState();
}

class _TestRouteState extends State<TestRoute> {
  Widget _model = ControlledAnimation(
    playback: Playback.MIRROR,
    duration: Duration(seconds: 3),
    tween: ColorTween(begin: Colors.blue, end: Colors.red),
    builder: (BuildContext context, dynamic value) {
      return Container(
          color: value,
          width: box_size.width,
          height: box_size.height
        );
    },
  );
  Widget _defaultImage = Container(
    color: Colors.grey,
    width: box_size.width,
    height: box_size.height,
    child: Center(
      child: Icon(Icons.photo_size_select_actual)
    ),
  );
  WidgetRecorderSimpleController _simpleController = WidgetRecorderSimpleController();
  Uint8List _imageBytes;
  Iterable<bool> _selections = [true, false];
  int _currentSelection = 0;
  double _sliderValue = 1;
  bool _pauseRecording = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Widget Recorder - Example'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(10.0),
        child: SizedBox.expand(
          child: Column(
            children: <Widget>[
              Spacer(flex: 1),
              Flexible(
                flex: 8,
                child: FittedBox(
                  fit: BoxFit.contain,
                  child: WidgetRecorder(
                    child: _model,
                    controller: _currentSelection == 0
                      ? _simpleController
                      : WidgetRecorderPeriodicController(
                          pause: _pauseRecording,
                          delay: Duration(seconds: _sliderValue.toInt())
                        ),
                    onSnapshotTaken: (WidgetRecorderSnapshot snapshot) {
                      Uint8List bytes = snapshot.byteData.buffer.asUint8List();

                      setState(() {
                        _imageBytes = bytes;
                      });
                    },
                  ),
                ),
              ),
              Spacer(flex: 1),
              Flexible(
                flex: 8,
                child: FittedBox(
                  child: SizedBox(
                    width: box_size.width,
                    height: box_size.height,
                    child: _imageBytes == null
                      ? _defaultImage
                      : Image.memory(_imageBytes, gaplessPlayback: true),
                  ),
                ),
              ),
              Spacer(flex: 1),
              Flexible(
                flex: 1,
                child: _selections.elementAt(1)
                  ? Slider(
                      min: 1,
                      max: 10,
                      divisions: 9,
                      value: _sliderValue,
                      label: '${_sliderValue.toInt()}s',
                      onChanged: (double value) {
                        setState(() {
                          _sliderValue = value;
                        });
                      },
                    )
                  : Container(),
              ),
              Flexible(
                flex: 1,
                child: _selections.elementAt(0)
                  ? RaisedButton(
                      onPressed: _simpleController.takeSnapshot,
                      child: Icon(Icons.camera_enhance),
                    )
                  : RaisedButton(
                      child: Icon(_pauseRecording ? Icons.play_arrow : Icons.pause),
                      onPressed: () {
                        setState(() {
                          _pauseRecording = !_pauseRecording;
                        });
                      }
                    )
              ),
              Spacer(flex: 1),
              Flexible(
                flex: 1,
                child: ToggleButtons(
                  children: <Widget>[
                    Icon(Icons.camera_alt),
                    Icon(Icons.videocam)
                  ],
                  isSelected: _selections,
                  onPressed: (int idx) {
                    if (_currentSelection != idx) {
                      List<bool> newSelections = [];
                      
                      for (int i = 0; i < _selections.length; i++) {
                        newSelections.add(i == idx);
                      }

                      setState(() {
                        _currentSelection = idx;
                        _selections = newSelections;
                      });
                    }
                  },
                )
              )
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  widget_recorder: ^0.3.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:widget_recorder/widget_recorder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
26
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on May 26, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test