доброе утро, я новичок в Flutter, я хочу использовать пакет dio для загрузки PDF-файла по URL-адресу с помощью кнопки. но когда я нажимаю кнопку, ничего не происходит/нет уведомления о загрузке файла на моем смартфоне (но файл был успешно загружен и сохранен в data/com.example.button/files). как вывести на смартфон уведомление о ходе загрузки. Ниже приведен код кнопки. спасибо большое
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:path_provider/path_provider.dart' as path;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
Stack(
alignment: Alignment.topCenter,
children: [
Container(
height: 400,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(50),
bottomRight: Radius.circular(50))),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
SizedBox(
height: 27,
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 5),
SizedBox(height: 20),
Container(
width: 150,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
18.0),
side: BorderSide()))),
onPressed: () {
downloadBook(
downloadLink:
"https://www.w3.org/WAI/ER/tests/xhtml/t ... /dummy.pdf",
title: "test");
},
child: Text(
"Download",
style: TextStyle(color: Colors.white),
),
),
),
],
)),
],
)
],
),
),
)
],
),
],
),
),
),
);
}
}
а вот код метода downloadBook
downloadBook({String? downloadLink, String? title}) async {
var dio;
if (await Permission.storage.request().isGranted) {
final downloadPath = await path.getExternalStorageDirectory();
var filePath = downloadPath!.path + '/$title.pdf';
dio = Dio();
await dio.download(downloadLink, filePath).then((value) {
dio.close();
}).catchError((Object e) {
Fluttertoast.showToast(
msg: "Terjadi kesalahan. Download gagal.", timeInSecForIosWeb: 1);
});
} else {
}
}
а вот код из androidmanifest.xml
Подробнее здесь: https://stackoverflow.com/questions/692 ... l-with-dio
Flutter-загрузить файл PDF с URL-адреса с помощью dio ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1770905310
Anonymous
доброе утро, я новичок в Flutter, я хочу использовать пакет dio для загрузки PDF-файла по URL-адресу с помощью кнопки. но когда я нажимаю кнопку, ничего не происходит/нет уведомления о загрузке файла на моем смартфоне (но файл был успешно загружен и сохранен в data/com.example.button/files). как вывести на смартфон уведомление о ходе загрузки. Ниже приведен код кнопки. спасибо большое
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:path_provider/path_provider.dart' as path;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
Stack(
alignment: Alignment.topCenter,
children: [
Container(
height: 400,
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(50),
bottomRight: Radius.circular(50))),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
SizedBox(
height: 27,
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 5),
SizedBox(height: 20),
Container(
width: 150,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
18.0),
side: BorderSide()))),
onPressed: () {
downloadBook(
downloadLink:
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
title: "test");
},
child: Text(
"Download",
style: TextStyle(color: Colors.white),
),
),
),
],
)),
],
)
],
),
),
)
],
),
],
),
),
),
);
}
}
а вот код метода downloadBook
downloadBook({String? downloadLink, String? title}) async {
var dio;
if (await Permission.storage.request().isGranted) {
final downloadPath = await path.getExternalStorageDirectory();
var filePath = downloadPath!.path + '/$title.pdf';
dio = Dio();
await dio.download(downloadLink, filePath).then((value) {
dio.close();
}).catchError((Object e) {
Fluttertoast.showToast(
msg: "Terjadi kesalahan. Download gagal.", timeInSecForIosWeb: 1);
});
} else {
}
}
а вот код из androidmanifest.xml
Подробнее здесь: [url]https://stackoverflow.com/questions/69230513/flutter-download-file-pdf-from-url-with-dio[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия