Skip to content

Commit

Permalink
add file name indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Nov 22, 2021
1 parent 388a34a commit e79e774
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 12 deletions.
112 changes: 100 additions & 12 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,109 @@ class _HomePageState extends State<HomePage>
children: [
const Spacer(flex: 9),
if (_fileNotifier.loading)
Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(500),
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.25,
child: LinearProgressIndicator(
backgroundColor:
Colors.white.withOpacity(0.1),
color: Colors.white,
minHeight: 2,
if (_fileNotifier.zipfileName == '')
Padding(
padding: const EdgeInsets.only(bottom: 24.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(500),
child: SizedBox(
width:
MediaQuery.of(context).size.width * 0.25,
child: LinearProgressIndicator(
backgroundColor:
Colors.white.withOpacity(0.1),
color: Colors.white,
minHeight: 2,
),
),
),
)
else
Container(
padding: const EdgeInsets.fromLTRB(12, 4, 12, 4),
margin: const EdgeInsets.only(bottom: 24.0),
width: MediaQuery.of(context).size.width * 0.25,
height: 48,
decoration: BoxDecoration(
color: Colors.white12,
borderRadius: BorderRadius.circular(6),
border: Border.all(
color: Colors.white.withOpacity(0.05),
width: 0.5,
),
),
child: Row(
children: [
Container(
width: 24,
height: 24,
decoration: BoxDecoration(
color: Colors.white12,
borderRadius: BorderRadius.circular(4),
border: Border.all(
color: Colors.white.withOpacity(0.05),
width: 0.5,
),
),
child: Center(
child: Text(
_fileNotifier.zipfileName[0],
style: GoogleFonts.poppins(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
const SizedBox(width: 12),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
SizedBox(
width: (MediaQuery.of(context)
.size
.width *
0.25) -
24 -
38,
child: Text(
_fileNotifier.zipfileName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.poppins(
fontSize: 10,
fontWeight: FontWeight.normal,
color: Colors.white,
),
),
),
const SizedBox(height: 8),
ClipRRect(
borderRadius:
BorderRadius.circular(500),
child: SizedBox(
width: (MediaQuery.of(context)
.size
.width *
0.25) -
24 -
38,
child: LinearProgressIndicator(
backgroundColor:
Colors.white.withOpacity(0.1),
color: Colors.white,
minHeight: 3,
),
),
),
])
],
),
),
),
if (_fileNotifier.fileLink != null)
Row(
mainAxisSize: MainAxisSize.min,
Expand Down
1 change: 1 addition & 0 deletions lib/providers/file_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class FileNotifier with ChangeNotifier {
bool get loading => _fileService.loading;
bool get processing => _fileService.processing;
String? get fileLink => _fileService.fileLink;
String get zipfileName => _fileService.zipfileName;

Future<void> getLinkFromFilePicker() async {
await _fileService.getLinkFromFilePicker();
Expand Down
6 changes: 6 additions & 0 deletions lib/services/file_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ import 'package:file_picker/file_picker.dart';
import 'package:odin/services/github_service.dart';
import 'package:odin/services/locator.dart';
import 'package:odin/services/zip_service.dart';
import 'package:path/path.dart';

class FileService {
final _githubService = locator<GithubService>();
final _zipService = locator<ZipService>();
bool loading = false;
bool processing = false;
String? fileLink;
String zipfileName = '';

Future<void> getLinkFromFilePicker() async {
fileLink = null;
FilePickerResult? result =
await FilePicker.platform.pickFiles(allowMultiple: true);
final String? _path;
if (result != null) {
zipfileName = '';
loading = true;
processing = true;
List<File> files = result.paths.map((path) => File(path!)).toList();
final zippedFile = await _zipService.zipFile(fileToZips: files);
zipfileName = basename(zippedFile.path);
processing = false;
_path = await _githubService.uploadFileAnonymous(zippedFile);
loading = false;
Expand All @@ -36,11 +40,13 @@ class FileService {
fileLink = null;
final String? _path;
if (urls.isNotEmpty) {
zipfileName = '';
loading = true;
processing = true;
final List<File> fileToZips =
urls.map((e) => File(e.toFilePath())).toList();
final zippedFile = await _zipService.zipFile(fileToZips: fileToZips);
zipfileName = basename(zippedFile.path);
processing = false;
_path = await _githubService.uploadFileAnonymous(zippedFile);
loading = false;
Expand Down

0 comments on commit e79e774

Please sign in to comment.