Created
October 6, 2019 05:22
-
-
Save ritshpatidar/f31933b885670e468a8e9117e8314901 to your computer and use it in GitHub Desktop.
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
//Put this code in the class which extens State class | |
static const platform = const MethodChannel('samples.flutter.dev/filesChannel'); //used to connect with Java/Kotlin | |
List<dynamic> fileNames = <dynamic>[]; | |
Future<void> _invokeNativeFun(int flag) async { | |
String s; | |
try { | |
if(flag == 0) | |
fileNames = await platform.invokeMethod('getNames'); //getNames function called from Kotlin/Java | |
} on PlatformException catch (e) { | |
s = "Failed: '${e.message}'."; //you can print it | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return FutureBuilder( | |
future: _invokeNativeFun(0), | |
builder: (context, snapshot){ | |
if(snapshot.connectionState == ConnectionState.done){ | |
return ListView.builder( | |
itemCount: fileNames.length, | |
itemBuilder: (BuildContext context, int index) => buildBody(context, index), | |
); | |
} else { | |
return Center(child: CircularProgressIndicator()); | |
} | |
} | |
); | |
} | |
Widget buildBody(BuildContext context, int index){ | |
return Text(fileNames[index],style:TextStyle(fontSize:20.0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment