Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arcticfox1919/flutter_lua_dardo
This is an extension of the LuaDardo library.LuaDardo library allows Flutter to execute Lua scripts, and this library which mainly wraps some of Flutter's interfaces, which gives Flutter the ability to dynamically update and generate interfaces using remote scripts in places where UI styles need to be changed frequently.
https://github.com/arcticfox1919/flutter_lua_dardo
dart flutter lua luadardo
Last synced: 8 days ago
JSON representation
This is an extension of the LuaDardo library.LuaDardo library allows Flutter to execute Lua scripts, and this library which mainly wraps some of Flutter's interfaces, which gives Flutter the ability to dynamically update and generate interfaces using remote scripts in places where UI styles need to be changed frequently.
- Host: GitHub
- URL: https://github.com/arcticfox1919/flutter_lua_dardo
- Owner: arcticfox1919
- License: apache-2.0
- Created: 2020-12-14T18:09:14.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-29T20:16:48.000Z (almost 3 years ago)
- Last Synced: 2023-08-20T21:58:46.396Z (about 1 year ago)
- Topics: dart, flutter, lua, luadardo
- Language: Dart
- Homepage:
- Size: 32.2 KB
- Stars: 31
- Watchers: 6
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_lua_dardo
This is an extension of the [LuaDardo](https://github.com/arcticfox1919/LuaDardo) library.LuaDardo library allows Flutter to execute Lua scripts, and this library which mainly wraps some of Flutter's interfaces, which gives Flutter the ability to dynamically update and generate interfaces using remote scripts in places where UI styles need to be changed frequently.
Please note that this is an experimental exploration. It only encapsulates a few simple Widgets. Others are welcome to encapsulate more Widgets for Lua.
![](https://gitee.com/arcticfox1919/ImageHosting/raw/master/img/GIF_2021-5-11_21-44-49.gif)
## Usage
New Lua script `test.lua`:
```lua
function getContent1()
return Row:new({
children={
GestureDetector:new({
onTap=function()
flutter.debugPrint("--------------onTap--------------")
end,child=Text:new("click here")}),
Text:new("label1"),
Text:new("label2"),
Text:new("label3"),
},
mainAxisAlign=MainAxisAlign.spaceEvenly,
})
endfunction getContent2()
return Column:new({
children={
Row:new({
children={Text:new("Hello"),Text:new("Flutter")},
mainAxisAlign=MainAxisAlign.spaceAround
}),
Image:network('https://gitee.com/arcticfox1919/ImageHosting/raw/master/img/flutter_lua_test.png'
,{fit=BoxFit.cover})
},
mainAxisSize=MainAxisSize.min,
crossAxisAlign=CrossAxisAlign.center
})
end
```In your Flutter project, add the dependency. `pubspec.yaml`
```yaml
dependencies:
flutter_lua_dardo: ^0.0.2
```Add Dart code:
```dart
class _MyHomePageState extends State {
LuaState _ls;
bool isChange = false;
@override
void initState() {
loadLua();
super.initState();
}
void loadLua() async {
String src = await rootBundle.loadString('assets/test.lua');
try {
LuaState ls = LuaState.newState();
ls.openLibs();
FlutterLua.open(ls);
FlutterWidget.open(ls);
ls.doString(src);
setState(() {
_ls = ls;
});
} catch (e) {
print(e);
}
}@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
alignment: Alignment.center,
child: _ls == null
? CircularProgressIndicator()
// call the specified Lua function
: FlutterWidget.findViewByName(
_ls, isChange ? "getContent2" : "getContent1"),
),
floatingActionButton: FloatingActionButton(
child: Icon(CupertinoIcons.arrow_swap),
onPressed: (){
setState(() {
isChange = !isChange;
});
},
),
);
}
}
```**To learn how to bind the Dart class to Lua, you can view this [example](https://github.com/arcticfox1919/flutter_lua_dardo/tree/master/test).**
For usage of LuaDardo, see [here](https://github.com/arcticfox1919/libd/blob/main/README.md).