How to pass Map type arguments to EvalWidget?
RaydowCharole opened this issue · comments
Hi, recently I successfully passed a String type variable to EvalWidget, but something went wrong when I try to pass a Map.
I tried to pass a map directly, I also tried to pass $Map.wrap(map)
, but none of them worked.
My Flutter version: 3.7.12
flutter_eval version: 0.6.0
Here is my code 👇
import 'package:flutter/material.dart';
import 'package:flutter_eval/widgets.dart';
import 'package:flutter_eval/flutter_eval.dart';
import 'package:dart_eval/dart_eval_bridge.dart';
import 'package:dart_eval/stdlib/core.dart';
void main() {
runApp(const MainApp());
}
const String code = '''
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
Map<String, dynamic> map;
// Map<String, dynamic> map = {'title': 'Hello'};
MyWidget(this.map, {super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
map['title'],
style: const TextStyle(fontSize: 50),
),
),
);
}
}
''';
const Map<String, dynamic> map = {'title': 'Hello World'};
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: EvalWidget(
packages: const {
'example': {'main.dart': code}
},
assetPath: 'assets/001.evc',
library: 'package:example/main.dart',
function: 'MyWidget.',
args: [
$Map.wrap(map),
null,
],
),
);
}
}
Looking for a solution. Thanks!
By the way, FontWeight.w100
to FontWeight.w900
worked, but Null check operator used on a null value
error occur when using FontWeight.bold
or FontWeight.normal
.
Besides, is it possible to use custom fonts?
In order to pass a Map you must wrap the values it contains:
final map = {$String('title'): $String('Hello World')};
You can also use runtime.wrapRecursive()
to do this automatically if the map contains only primitive values.
FontWeight issue is fixed in v0.6.1.
Custom fonts can be added in the host app's assets and then used in the flutter_eval code.