LCOV - code coverage report
Current view: | top level - src/widgets - story_render.dart (source / functions) |  |  | Hit | Total | Coverage
Test: | lcov.info |  | Lines: | 1 | 28 | 3.6 %
Date: | 2021-10-11 06:57:03 |  | Functions: | 0 | 0 | -

              Line data    Source code
           1             : import 'package:flutter/material.dart';
           2             : import 'package:vector_math/vector_math_64.dart' as vector;
           3             : import 'package:widgetbook/src/models/organizers/organizers.dart';
           4             : import 'package:widgetbook/src/providers/canvas_provider.dart';
           5             : import 'package:widgetbook/src/providers/zoom_provider.dart';
           6             : import 'package:widgetbook/src/widgets/device_render.dart';
           7             :
           8             : class StoryRender extends StatefulWidget {
           9          14 :   const StoryRender({Key? key}) : super(key: key);
          10             :
          11           0 :   @override
          12           0 :   _StoryState createState() => _StoryState();
          13             : }
          14             :
          15             : class _StoryState extends State<StoryRender> {
          16             :   TransformationController controller = TransformationController(
          17             :     Matrix4.identity(),
          18             :   );
          19             :
          20           0 :   Widget _buildStory() {
          21           0 :     final state = CanvasProvider.of(context)!.state;
          22           0 :     if (state.selectedStory != null) {
          23           0 :       return _buildCanvas(state.selectedStory!);
          24             :     }
          25             :
          26           0 :     return Center(
          27           0 :       child: Container(),
          28             :     );
          29             :   }
          30             :
          31           0 :   void _updateController() {
          32           0 :     final state = ZoomProvider.of(context)!.state;
          33             :
          34           0 :     final oldMatrix = controller.value;
          35             :
          36           0 :     final translation = oldMatrix.getTranslation();
          37             :
          38           0 :     final rotation = oldMatrix.getRotation();
          39           0 :     oldMatrix.setFromTranslationRotationScale(
          40             :       translation,
          41           0 :       vector.Quaternion.fromRotation(rotation),
          42           0 :       vector.Vector3.all(state.zoomLevel),
          43             :     );
          44           0 :     controller = TransformationController(oldMatrix);
          45             :   }
          46             :
          47           0 :   Widget _buildCanvas(Story story) {
          48           0 :     _updateController();
          49             :
          50           0 :     return InteractiveViewer(
          51             :       boundaryMargin: const EdgeInsets.all(double.infinity),
          52             :       minScale: 0.25,
          53             :       maxScale: 5,
          54             :       constrained: false,
          55           0 :       transformationController: controller,
          56           0 :       onInteractionUpdate: (ScaleUpdateDetails details) {
          57           0 :         ZoomProvider.of(context)!
          58           0 :             .setScale(controller.value.getMaxScaleOnAxis());
          59             :       },
          60           0 :       child: DeviceRender(
          61             :         story: story,
          62             :       ),
          63             :     );
          64             :   }
          65             :
          66           0 :   @override
          67             :   Widget build(BuildContext context) {
          68           0 :     return _buildStory();
          69             :   }
          70             : }

Generated by: LCOV version 1.15