📌  相关文章
📜  从文件到列表视图颤动 - 无论代码示例

📅  最后修改于: 2022-03-11 14:57:01.010000             🧑  作者: Mango

代码示例1
// add dependancy in pubspec.yaml
 path_provider:

 import 'dart:io' as io;
    import 'package:path_provider/path_provider.dart';

    //Declare Globaly
      String directory;
      List file = new List();
      @override
      void initState() {
        // TODO: implement initState
        super.initState();
        _listofFiles();
      }

    // Make New Function
    void _listofFiles() async {
        directory = (await getApplicationDocumentsDirectory()).path;
        setState(() {
          file = io.Directory("$directory/resume/").listSync();  //use your folder name insted of resume.
        });
      }

    // Build Part
    @override
      Widget build(BuildContext context) {
        return MaterialApp(
          navigatorKey: navigatorKey,
          title: 'List of Files',
          home: Scaffold(
            appBar: AppBar(
              title: Text("Get List of Files with whole Path"),
            ),
            body: Container(
              child: Column(
                children: [
                  // your Content if there
                  Expanded(
                    child: ListView.builder(
                        itemCount: file.length,
                        itemBuilder: (BuildContext context, int index) {
                          return Text(file[index].toString());
                        }),
                  )
                ],
              ),
            ),
          ),
        );
      }