Answers for "from file to list view flutter"

0

from file to list view flutter

// 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: <Widget>[
                  // your Content if there
                  Expanded(
                    child: ListView.builder(
                        itemCount: file.length,
                        itemBuilder: (BuildContext context, int index) {
                          return Text(file[index].toString());
                        }),
                  )
                ],
              ),
            ),
          ),
        );
      }
Posted by: Guest on June-01-2021

Browse Popular Code Answers by Language