lecle_downloads_path_provider 0.0.1 copy "lecle_downloads_path_provider: ^0.0.1" to clipboard
lecle_downloads_path_provider: ^0.0.1 copied to clipboard

outdated

A new Flutter project.

example/lib/main.dart

import 'dart:async';

import 'package:lecle_downloads_path_provider/lecle_downloads_path_provider.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _downloadsPath = 'Unknown';

  @override
  void initState() {
    super.initState();
    initDownloadsDirectoryPath();
  }

  Future<void> initDownloadsDirectoryPath() async {
    String downloadsPath;
    try {
      downloadsPath = (await DownloadsPath.downloadsDirectory)?.path ?? "Downloads path doesn't exist";
    } catch (e) {
      downloadsPath = 'Failed to get downloads paths';
    }

    if (!mounted) return;

    setState(() {
      _downloadsPath = downloadsPath;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Downloads path example app'),
          centerTitle: true,
        ),
        body: Center(
          child: Text('Downloads path:\n $_downloadsPath\n', textAlign: TextAlign.center),
        ),
      ),
    );
  }
}