mirror of
https://github.com/rive-app/rive-flutter.git
synced 2025-05-19 22:36:51 +08:00
basic text test
adding a basic text test to get to the bottom of text not working Diffs= 66e234066 basic text test (#5718) b69ae1312 Lift tess decoders into a static lib (#5709) Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
This commit is contained in:
@ -1 +1 @@
|
|||||||
913760d979f6ab9b54ac510726649dc0980f6b15
|
66e234066f31e22208005a4583b4f423a86c4281
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
## 0.11.9
|
||||||
|
|
||||||
|
- Fix issue showing text when the default font is not available at `assets/fonts/Inter-Regular.ttf`. We will set first valid font we encounter in a rive file as default font instead.
|
||||||
|
|
||||||
## 0.11.8
|
## 0.11.8
|
||||||
|
|
||||||
- Fix text origin changing updating text offset.
|
- Fix text origin changing updating text offset.
|
||||||
|
BIN
example/assets/text_flutter.riv
Normal file
BIN
example/assets/text_flutter.riv
Normal file
Binary file not shown.
22
example/lib/basic_text.dart
Normal file
22
example/lib/basic_text.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:rive/rive.dart';
|
||||||
|
|
||||||
|
/// Basic example playing a Rive animation from a packaged asset.
|
||||||
|
class BasicText extends StatelessWidget {
|
||||||
|
const BasicText({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Basic Text'),
|
||||||
|
),
|
||||||
|
body: const Center(
|
||||||
|
child: RiveAnimation.asset(
|
||||||
|
'assets/text_flutter.riv',
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ import 'package:rive_example/simple_machine_listener.dart';
|
|||||||
import 'package:rive_example/simple_state_machine.dart';
|
import 'package:rive_example/simple_state_machine.dart';
|
||||||
import 'package:rive_example/skinning_demo.dart';
|
import 'package:rive_example/skinning_demo.dart';
|
||||||
import 'package:rive_example/state_machine_skills.dart';
|
import 'package:rive_example/state_machine_skills.dart';
|
||||||
|
import 'package:rive_example/basic_text.dart';
|
||||||
|
|
||||||
void main() => runApp(
|
void main() => runApp(
|
||||||
MaterialApp(
|
MaterialApp(
|
||||||
@ -54,6 +55,7 @@ class _RiveExampleAppState extends State<RiveExampleApp> {
|
|||||||
const _Page('State Machine with Listener', StateMachineListener()),
|
const _Page('State Machine with Listener', StateMachineListener()),
|
||||||
const _Page('Skinning Demo', SkinningDemo()),
|
const _Page('Skinning Demo', SkinningDemo()),
|
||||||
const _Page('Animation Carousel', AnimationCarousel()),
|
const _Page('Animation Carousel', AnimationCarousel()),
|
||||||
|
const _Page('Basic Text', BasicText()),
|
||||||
const _Page('Custom Asset Loading', CustomAssetLoading()),
|
const _Page('Custom Asset Loading', CustomAssetLoading()),
|
||||||
const _Page('Custom Cached Asset Loading', CustomCachedAssetLoading()),
|
const _Page('Custom Cached Asset Loading', CustomCachedAssetLoading()),
|
||||||
];
|
];
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:rive/src/asset.dart';
|
import 'package:rive/src/asset.dart';
|
||||||
|
import 'package:rive/src/debug.dart';
|
||||||
import 'package:rive/src/rive_core/assets/file_asset.dart';
|
import 'package:rive/src/rive_core/assets/file_asset.dart';
|
||||||
import 'package:rive/src/utilities/utilities.dart';
|
import 'package:rive/src/utilities/utilities.dart';
|
||||||
|
|
||||||
@ -49,13 +49,11 @@ class CDNAssetLoader extends FileAssetLoader {
|
|||||||
Uint8List.view(res.bodyBytes.buffer),
|
Uint8List.view(res.bodyBytes.buffer),
|
||||||
);
|
);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
// only print in debug
|
printDebugMessage(
|
||||||
assert(() {
|
'''Unable to parse response ${asset.runtimeType}.
|
||||||
debugPrint('''Unable to parse response ${asset.runtimeType}.
|
|
||||||
- Url: $url
|
- Url: $url
|
||||||
- Exception: $e''');
|
- Exception: $e''',
|
||||||
return true;
|
);
|
||||||
}());
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:rive/src/asset_loader.dart';
|
import 'package:rive/src/asset_loader.dart';
|
||||||
import 'package:rive/src/core/core.dart';
|
import 'package:rive/src/core/core.dart';
|
||||||
|
import 'package:rive/src/debug.dart';
|
||||||
import 'package:rive/src/rive_core/assets/file_asset.dart';
|
import 'package:rive/src/rive_core/assets/file_asset.dart';
|
||||||
import 'package:rive/src/rive_core/assets/file_asset_contents.dart';
|
import 'package:rive/src/rive_core/assets/file_asset_contents.dart';
|
||||||
|
|
||||||
@ -35,15 +36,13 @@ class FileAssetImporter extends ImportStackObject {
|
|||||||
// try to get them out of band
|
// try to get them out of band
|
||||||
assetLoader?.load(fileAsset).then((loaded) {
|
assetLoader?.load(fileAsset).then((loaded) {
|
||||||
// TODO: improve error logging
|
// TODO: improve error logging
|
||||||
// Only print if in debug mode.
|
if (!loaded) {
|
||||||
assert(() {
|
printDebugMessage(
|
||||||
if (!loaded) {
|
'''Rive asset (${fileAsset.name}) was not able to load:
|
||||||
debugPrint('''Rive asset (${fileAsset.name}) was not able to load:
|
|
||||||
- Unique file name: ${fileAsset.uniqueFilename}
|
- Unique file name: ${fileAsset.uniqueFilename}
|
||||||
- Asset id: ${fileAsset.id}''');
|
- Asset id: ${fileAsset.id}''',
|
||||||
}
|
);
|
||||||
return true;
|
}
|
||||||
}());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return super.resolve();
|
return super.resolve();
|
||||||
|
9
lib/src/debug.dart
Normal file
9
lib/src/debug.dart
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
/// Print a message only when running in debug.
|
||||||
|
void printDebugMessage(String message) {
|
||||||
|
assert(() {
|
||||||
|
debugPrint(message);
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
}
|
@ -3,6 +3,7 @@ import 'dart:typed_data';
|
|||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:rive/src/debug.dart';
|
||||||
import 'package:rive/src/generated/text/text_base.dart';
|
import 'package:rive/src/generated/text/text_base.dart';
|
||||||
import 'package:rive/src/rive_core/component_dirt.dart';
|
import 'package:rive/src/rive_core/component_dirt.dart';
|
||||||
import 'package:rive/src/rive_core/text/styled_text.dart';
|
import 'package:rive/src/rive_core/text/styled_text.dart';
|
||||||
@ -77,6 +78,15 @@ class Text extends TextBase with TextStyleContainer {
|
|||||||
|
|
||||||
int get unicharCount => _unicharCount;
|
int get unicharCount => _unicharCount;
|
||||||
|
|
||||||
|
Font? getFirstAvailableFont() {
|
||||||
|
for (final run in runs) {
|
||||||
|
if (run.style?.font != null) {
|
||||||
|
return run.style?.font;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
StyledText makeStyled(
|
StyledText makeStyled(
|
||||||
Font defaultFont, {
|
Font defaultFont, {
|
||||||
bool forEditing = false,
|
bool forEditing = false,
|
||||||
@ -179,7 +189,6 @@ class Text extends TextBase with TextStyleContainer {
|
|||||||
_syncRuns();
|
_syncRuns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Mat2D get originTransform => Mat2D.multiply(
|
Mat2D get originTransform => Mat2D.multiply(
|
||||||
Mat2D(),
|
Mat2D(),
|
||||||
worldTransform,
|
worldTransform,
|
||||||
@ -472,6 +481,9 @@ class Text extends TextBase with TextStyleContainer {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Question (max): is it safer to simply skip computing Shape if we
|
||||||
|
// have no default font?
|
||||||
assert(_defaultFont != null);
|
assert(_defaultFont != null);
|
||||||
var defaultFont = _defaultFont!;
|
var defaultFont = _defaultFont!;
|
||||||
_modifierShape?.dispose();
|
_modifierShape?.dispose();
|
||||||
@ -539,6 +551,11 @@ class Text extends TextBase with TextStyleContainer {
|
|||||||
_defaultFont = Font.decode(fontAsset.buffer.asUint8List());
|
_defaultFont = Font.decode(fontAsset.buffer.asUint8List());
|
||||||
// Reshape now that we have font.
|
// Reshape now that we have font.
|
||||||
markShapeDirty();
|
markShapeDirty();
|
||||||
|
}).onError((error, stackTrace) {
|
||||||
|
_defaultFont = getFirstAvailableFont();
|
||||||
|
if (_defaultFont != null) {
|
||||||
|
markShapeDirty();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
computeShape();
|
computeShape();
|
||||||
|
Reference in New Issue
Block a user