最佳实践案例:
void main() {
final dynamicVariable = 'hello';
print(dynamicVariable); // hello
declare_dynamic newVariable = 'world';
print(newVariable); // world
}
void main() {
bool usePluginA = true;
declare_dynamic plugin;
if (usePluginA) {
plugin = PluginA();
} else {
plugin = PluginB();
}
plugin.run();
}
class MyClass {
void myMethod() {
print('Hello from myMethod!');
}
}
void main() {
declare_dynamic myObject = MyClass();
myObject.myMethod(); // Hello from myMethod!
}