Coder Social home page Coder Social logo

nima-flutter's Introduction

Nima-Flutter

Flutter runtime written in Dart with SKIA based rendering.

Installation

Add nima as a dependency in your pubspec.yaml file.

Exporting for Flutter

Export from Nima with the Export to Engine menu. In the Engine drop down, choose Generic.

Adding Assets

Once you've exported your character file. Add the .nima file and and the .png atlas files to your project's Flutter assets.

Make sure the .png files are at the same level as the.nima file. If you renamed your .nima file, make sure to rename your assets accordingly.

In the future we may opt to package the images into the .nima file as we do for WebGL. Let us know if you're in favor of this!

Example

Take a look at the provided example application for how to use the NimaActor widget with an exported Nima character.

Usage

The easiest way to get started is by using the provided NimaActor widget. This is a stateless Flutter widget that allows for one Nima character with one active animation playing. You can change the currently playing animation by changing the animation property's name. You can also specify the mixSeconds to determine how long it takes for the animation to interpolate from the previous one. A value of 0 means that it will just pop to the new animation. A value of 0.5 will mean it takes half of a second to fully mix the new animation on top of the old one.

import 'package:nima/nima_actor.dart';
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new NimaActor("assets/Hop", alignment:Alignment.center, fit:BoxFit.contain, animation:"idle");
  }
}

Advanced Usage

For more advanced usage such as creating views with multiple Nima characters, multiple active animations, and controllers, please refer to the internals of nima_actor.dart to get acquainted with the API. We'll be posting more detailed tutorials and documentation regarding the inner workings of the API soon.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request.

License

See the LICENSE file for license rights and limitations (MIT).

nima-flutter's People

Contributors

luigi-rosso avatar umberto-sonnino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nima-flutter's Issues

Pub get failed

Running "flutter packages get" in nima...
Error on line 22, column 3 of pubspec.yaml: A package may not list itself as a dependency.
nima: ^1.0.2
^^^^

pub get failed (65)
Process finished with exit code 65

Error on release build

I'm getting this error:

flutter: Loading actor filename assets/animation/welcome
[VERBOSE-2:shell.cc(181)] Dart Error: Unhandled exception:
RangeError (length): Invalid value: Not in range 0..8, inclusive: 8
#0 _List.[]= (dart:core/runtime/libarray.dart:0)
#1 Actor.readComponentsBlock (package:nima/nima/actor.dart:560)
#2 Actor.load (package:nima/nima/actor.dart:421)
#3 FlutterActor.loadFromBundle (package:nima/nima.dart:197)

On debug mode it's fine, this happens only if i run the release build.
Thanks.

build error

lutter/.pub-cache/hosted/pub.flutter-io.cn/nima-1.0.3/lib/nima.dart:119:18: Error:
The argument type 'Int32List' can't be assigned to the parameter type 'Uint16List'.
 - 'Int32List' is from 'dart:typed_data'.
 - 'Uint16List' is from 'dart:typed_data'.
Try changing the type of the parameter, or casting the argument to 'Uint16List'.
        indices: _indices, textureCoordinates: _uvBuffer);
                 ^
file:///Users/jintian/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/palette_generator-0.1.1/lib/palette_gene
rator.dart:188:29: Error: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type
'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart'
 ('file:///Users/jintian/development/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart'
 ('file:///Users/jintian/development/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
      stream.removeListener(imageListener);
                            ^
file:///Users/jintian/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/palette_generator-0.1.1/lib/palette_gene
rator.dart:194:31: Error: The argument type 'void Function(ImageInfo, bool)' can't be assigned to the parameter type
'ImageStreamListener'.
 - 'ImageInfo' is from 'package:flutter/src/painting/image_stream.dart'
 ('file:///Users/jintian/development/flutter/packages/flutter/lib/src/painting/image_stream.dart').
 - 'ImageStreamListener' is from 'package:flutter/src/painting/image_stream.dart'
 ('file:///Users/jintian/development/flutter/packages/flutter/lib/src/painting/image_stream.dart').
Try changing the type of the parameter, or casting the argument to 'ImageStreamListener'.
        stream.removeListener(imageListener);
                              ^

Error while running example given

The following is the error that I received while running the example app. Kindly have a look at this:

I/flutter (22356): ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (22356): The following assertion was thrown during a scheduler callback:
I/flutter (22356): setState() called after dispose(): WelcomeScreenState#1f5f4(lifecycle state: defunct, not mounted)
I/flutter (22356): This error happens if you call setState() on a State object for a widget that no longer appears in
I/flutter (22356): the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error
I/flutter (22356): can occur when code calls setState() from a timer or an animation callback. The preferred solution
I/flutter (22356): is to cancel the timer or stop listening to the animation in the dispose() callback. Another
I/flutter (22356): solution is to check the "mounted" property of this object before calling setState() to ensure the
I/flutter (22356): object is still in the tree.
I/flutter (22356): This error might indicate a memory leak if setState() is being called because another object is
I/flutter (22356): retaining a reference to this State object after it has been removed from the tree. To avoid memory
I/flutter (22356): leaks, consider breaking the reference to this object during dispose().

I tried resolving this to some extent using the mounted property of the Widget build however, it still throws the following error:
I/flutter (22356): ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (22356): The following NoSuchMethodError was thrown during a scheduler callback:
I/flutter (22356): The getter 'isLooping' was called on null.
I/flutter (22356): Receiver: null
I/flutter (22356): Tried calling: isLooping

Export generates a .nma instead of .nima?

I followed the steps for exporting to flutter, selecting export to engine, type generic, leaving the rest as default. This generates a zip with a .nma file instead of a .nima file which does not seem to be usable in flutter.

Update: I tried to manually change the file ending from .nma to .nima and then it works.

Error when loading assets

You can find my Flutter sample project here and the Nima sample here

I follow the steps define in the documentation

  • Export the Nima project with Generic. The export make a nma file extension instead of nima extension in your exemple. I try to rename the file with nima extension and the stacktrace error is the same
  • Declare assets in pubspec.yaml
  • Import nima dependency in pubspec.yaml
  • Add a NimaActor widget in the widget tree
import "dart:typed_data";

import 'package:flutter/material.dart';
import "package:flutter/services.dart" show rootBundle;
import 'package:nima/nima_actor.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // FIXME: To be removed, this is for testing the .nma asset is loaded
    rootBundle.load("assets/testBZ.nma").then((ByteData data) {
      debugPrint('DATA LOAD $data.runtimeType');
    }).catchError((error) {
      debugPrint('LOAD DATA ERROR, $error');
    });

    return Column(
      children: <Widget>[
        NimaActor("assets/testBZ",
            alignment: Alignment.center,
            fit: BoxFit.contain,
            animation: "idle"),
        Image.asset(
          'assets/testBZ.png',
        ),
      ],
    );
  }
}

As you can see, i add an Image widget for testing that the png asset in accessible in context, and i read the nma file too, it works.

Stacktrace

Launching lib/main.dart on iPhone X in debug mode...
Starting Xcode build...
Xcode build done.                                            6.2s
flutter: DATA LOAD Instance of '_ByteDataView'.runtimeType
[VERBOSE-2:shell.cc(184)] Dart Error: Unhandled exception:
Unable to load asset: assets/testBZ
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1      FlutterActor.loadFromBundle (package:nima/nima.dart:190:38)
<asynchronous suspension>
#2      NimaActorRenderObject.filename= (package:nima/nima_actor.dart:197:11)
#3      NimaActor.createRenderObject (package:nima/nima_actor.dart:44:9)
#4      RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4482:28)
#5      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
#6      MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
#7      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
#8      Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
#9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
#10     Element.rebuild (package:flut<…>
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performResize():
flutter: NimaActorRenderObject object was given an infinite size during layout.
flutter: This probably means that it is a render object that tries to be as big as possible, but it was put
flutter: inside another render object that allows its children to pick their own size.
flutter: The nearest ancestor providing an unbounded height constraint is:
flutter:   RenderFlex#c9289 NEEDS-LAYOUT NEEDS-PAINT
flutter:   creator: Column ← MyApp ← [root]
flutter:   parentData: <none>
flutter:   constraints: BoxConstraints(w=375.0, h=812.0)
flutter:   size: MISSING
flutter:   direction: vertical
flutter:   mainAxisAlignment: start
flutter:   mainAxisSize: max
flutter:   crossAxisAlignment: center
flutter:   verticalDirection: down
flutter: The constraints that applied to the NimaActorRenderObject were:
flutter:   BoxConstraints(0.0<=w<=375.0, 0.0<=h<=Infinity)
flutter: The exact size it was given was:
flutter:   Size(375.0, Infinity)
flutter: See https://flutter.io/layout/ for more information.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      RenderBox.debugAssertDoesMeetConstraints.<anonymous closure> (package:flutter/src/rendering/box.dart:1749:9)
flutter: #1      RenderBox.debugAssertDoesMeetConstraints (package:flutter/src/rendering/box.dart:1823:6)
flutter: #2      RenderBox.size=.<anonymous closure> (package:flutter/src/rendering/box.dart:1543:17)
flutter: #3      RenderBox.size= (package:flutter/src/rendering/box.dart:1543:65)
flutter: #4      NimaActorRenderObject.performResize (package:nima/nima_actor.dart:228:5)
flutter: #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1619:9)
flutter: #6      RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
flutter: #7      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #8      RenderView.performLayout (package:flutter/src/rendering/view.dart:147:13)
flutter: #9      RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
flutter: #10     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
flutter: #11     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
flutter: #12     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:677:13)
flutter: #13     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
flutter: #14     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #15     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #16     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7)
flutter: #18     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
flutter: #19     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
flutter: #20     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
flutter: (elided one frame from package dart:async)
flutter:
flutter: The following RenderObject was being processed when the exception was fired:
flutter:   NimaActorRenderObject#57fda NEEDS-LAYOUT NEEDS-PAINT
flutter:   creator: NimaActor ← Column ← MyApp ← [root]
flutter:   parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
flutter:   constraints: BoxConstraints(0.0<=w<=375.0, 0.0<=h<=Infinity)
flutter:   size: Size(375.0, Infinity)
flutter: This RenderObject has no descendants.
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: NimaActorRenderObject object was given an infinite size during layout.
Syncing files to device iPhone X...
flutter: Another exception was thrown: A RenderFlex overflowed by Infinity pixels on the bottom.
flutter: Another exception was thrown: NimaActorRenderObject object was given an infinite size during layout.

Completed callback is not being call

I'm using the latest version of the package (v 1.0.2) but the completed callback is not being call, animation status is always the last one called, either jump or attack.

NimaActor doesnt play on specific phone

Actually, i don't have any logs but my NimaActor just working in an Android Emulator but when I install the same app to my Mi 5 phone it doesn't play. I'm using this btw https://github.com/2d-inc/HistoryOfEverything/tree/master/app/assets/Recorded_history
It just has a candle burning effect and this works in an Android Emulator but on my phone, it shows up but without animation that burning animation...
I just wonder if you have any idea why this not works on my phone. I didn't check the logs but i cant check if you need too..

NimaActor("assets/nima/Recorded_history.nma",
            fit: BoxFit.scaleDown, animation: "Untitled")

Error during widget testing. (An animation is still running even after the widget tree was disposed)

Hi, I am getting this error while running a simple widget test:

The following message was thrown:
An animation is still running even after the widget tree was disposed.
...

This is the test:

testWidgets('DetailsPage displays properly', (WidgetTester tester) async {
    await tester.pumpWidget(
        Foo bar = FooFactory().create();
            MaterialApp(
              home: DetailsPage(foo: bar),
            ),
        );

    expect(find.byKey(Key('DetailsScaffoldKey')), findsOneWidget);
});

Any idea how i can fix this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.