Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:audiobook_player/presentation/library_page/library_page.dart';
- import 'package:file_picker/file_picker.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> {
- String _fileName;
- List<PlatformFile> _paths = [];
- List<String> _listOfFileName = <String>[];
- String _directoryPath;
- String _extension;
- bool _loadingPath = false;
- bool _multiPick = true;
- List<String> _listOfPaths;
- FileType _pickingType = FileType.audio;
- void _openFileExplorer() async {
- setState(() => _loadingPath = true);
- try {
- _directoryPath = null;
- _paths = (await FilePicker.platform.pickFiles(
- type: FileType.audio,
- allowMultiple: true,
- allowedExtensions: (_extension?.isNotEmpty ?? false)
- ? _extension?.replaceAll(' ', '')?.split(',')
- : null,
- ))
- ?.files;
- } on PlatformException catch (e) {
- print("Unsupported operation" + e.toString());
- } catch (ex) {
- print(ex);
- }
- if (!mounted) return;
- setState(() {
- _loadingPath = false;
- _fileName = _paths != null ? _paths.map((e) => e.name).toString() : '...';
- // _listOfFileName.add(_fileName);
- });
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text("Open Audiobook"),
- actions: <Widget>[
- InkWell(
- onTap: () async {
- setState(() {
- _openFileExplorer();
- });
- },
- child: Padding(
- padding: const EdgeInsets.all(15.0),
- child: Icon(Icons.add_circle_outline_rounded),
- ),
- ),
- ],
- ),
- body: Center(
- child: ElevatedButton(
- child: Text('Go to Library Page'),
- onPressed: () {
- Navigator.push(
- context,
- MaterialPageRoute(
- builder: (context) => LibraryPage(
- listOfFileName: _listOfFileName,
- paths: _paths,
- ),
- ),
- );
- },
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment