Im trying to fetch some file list from my local device and show it with my emulator. I have generated my code like this and this works fine when it is tested by the local terminal
import 'dart:io';
List<String> getPath(String path) {
Directory dir = Directory(path);
List<FileSystemEntity> files = dir.listSync();
return files.map((file) => file.toString()).toList();
}
main() {
Directory dir = Directory(
'C:/Users/jerrypc/flutter_projects/new_nft_3d/assets/3d_objects/');
print(dir.absolute);
List<FileSystemEntity> files = dir.listSync();
for (var file in files) {
print(file.toString());
}
}
However, what makes me crazy is that if I'm trying to call this with my flutter app testing on android emulator or web, it keeps spit outs that "file directory does not exists". I have doubt that if this error is caused by security issue or something. And I would really be appreciated how to solve it if it is really a security issue. This is my flutter code that keep causing error
import 'package:flutter/material.dart';
import 'package:model_viewer_plus/model_viewer_plus.dart';
import 'dart:io';
import '../functions/path_function.dart';
class Page1 extends StatelessWidget {
const Page1({super.key});
final AssetPath =
'C:/Users/jerrypc/flutter_projects/new_nft_3d/assets/3d_objects/';
@override
Widget build(BuildContext context) {
return Scaffold(
body: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),
itemBuilder: (context, index) {
return custom3dTile(index: index, path: AssetPath);
}));
}
}
Widget custom3dTile({required int index, required String path}) {
return ModelViewer(
src: getPath(path)[index],
alt: "A 3D model of an astronaut",
ar: true,
autoRotate: true,
cameraControls: true,
);
}