Created
December 30, 2024 22:33
-
-
Save rayliverified/1fc81f519ac25f5b61d1daec8030d883 to your computer and use it in GitHub Desktop.
main_test_function_apply_issue.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MaterialApp( | |
home: Scaffold( | |
body: Center( | |
child: DemoWidget(), | |
), | |
), | |
)); | |
} | |
class DemoWidget extends StatelessWidget { | |
const DemoWidget({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
// 1) Direct usage with literal named parameters (#width, #height) | |
createContainerWithDirectSymbols(), | |
const SizedBox(height: 20), | |
// 2) Using Function.apply with Symbol-based named parameters | |
createContainerWithDynamicNamedParameters(), | |
], | |
); | |
} | |
Widget createContainerWithDirectSymbols() { | |
try { | |
return Function.apply( | |
Container.new, | |
[], | |
{ | |
#width: 150.0, | |
#height: 50.0, | |
#color: Colors.red, | |
}, | |
) as Widget; | |
} catch (e) { | |
return Text('Error: $e'); | |
} | |
} | |
Widget createContainerWithDynamicNamedParameters() { | |
try { | |
return Function.apply( | |
Container.new, | |
[], | |
{ | |
Symbol('width'): 150.0, | |
Symbol('height'): 50.0, | |
Symbol('color'): Colors.red, | |
}, | |
) as Widget; | |
} catch (e) { | |
return Text('Error: $e'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment