tbib_downloader 2.1.1 copy "tbib_downloader: ^2.1.1" to clipboard
tbib_downloader: ^2.1.1 copied to clipboard

PlatformAndroid

This package for download file and open it you can display notifications and progress notification and can receive download bytes and total bytes.

example/lib/main.dart

import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:flutter/material.dart';
import 'package:tbib_downloader/tbib_downloader.dart';
import 'package:tbib_downloader_example/new_screen.dart';
import 'package:tbib_downloader_example/services/notification_services.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await TBIBDownloader().init();

  runApp(const App());
}

//app
class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Background downloader',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MainPage());
  }
}

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  double progress = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('download file'),
      ),

      // zip file url download
      /// pdf file total size issue is https://www.eurofound.europa.eu/sites/default/files/ef_publication/field_ef_document/ef1710en.pdf
      /// pdf file total size issue is https://freetestdata.com/wp-content/uploads/2022/11/Free_Test_Data_10.5MB_PDF.pdf
      body: Column(
        children: [
          //if (progress > 0)
          Align(
            alignment: Alignment.topCenter,
            child: LinearProgressIndicator(
              value: progress,
            ),
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () async {
                  var path = await TBIBDownloader().downloadFile(
                    context: context,
                    url: 'http://speedtest.ftp.otenet.gr/files/test10Mb.db',
                    receiveBytesAsMB: true,
                    fileName: 'dummy.bin',
                    directoryName: 'test',
                    onReceiveProgress: ({int? receivedBytes, int? totalBytes}) {
                      if (!context.mounted) {
                        return;
                      }
                      setState(() {
                        progress = (receivedBytes! / totalBytes!);
                      });
                    },
                  );
                  debugPrint('path $path');
                  if (!context.mounted) {
                    return;
                  }
                  setState(() {
                    progress = 0;
                  });
                },
                child: const Text('download'),
              ),
              const SizedBox(height: 20),
              ElevatedButton(
                onPressed: () async {
                  var path = await TBIBDownloader().downloadFile(
                    context: context,

                    url:
                        'https://file-examples.com/storage/fef44df12666d835ba71c24/2017/10/file-sample_150kB.pdf',
                    fileName: 'dummy1.pdf',
                    saveFileInDataApp: true,
                    directoryName: 'test',
                    // onReceiveProgress: ({int? count, int? total}) => debugPrint(
                    //     'count: $count, total: $total, progress: ${count! / total!}'),
                  );
                  debugPrint('path $path');
                },
                child: const Text('download 1'),
              ),
              const SizedBox(height: 20),
              // button close this page and go to new page
              ElevatedButton(
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const SecondPage(),
                    ),
                  );
                },
                child: const Text('go to second page'),
              ),
            ],
          )
        ],
      ),
    );
  }

  @override
  void initState() {
    super.initState();
    AwesomeNotifications().setListeners(
        onActionReceivedMethod: MyNotificationService.onActionReceivedMethod,
        onNotificationCreatedMethod:
            MyNotificationService.onNotificationCreatedMethod,
        onNotificationDisplayedMethod:
            MyNotificationService.onNotificationDisplayedMethod,
        onDismissActionReceivedMethod:
            MyNotificationService.onDismissActionReceivedMethod);
  }
}
25
likes
160
pub points
68%
popularity

Publisher

unverified uploader

This package for download file and open it you can display notifications and progress notification and can receive download bytes and total bytes.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

awesome_notifications, device_info_plus, dio, external_path, flutter, mime, open_file, path_provider, permission_handler, plugin_platform_interface, share_plus

More

Packages that depend on tbib_downloader