From 471ee77e03b4dd616d9d9dd0a2e31b74cec0209b Mon Sep 17 00:00:00 2001 From: LiquidatorCoder Date: Mon, 15 Nov 2021 13:34:24 +0530 Subject: [PATCH] add tooltip --- lib/pages/home_page.dart | 43 ++++++++++++++++++++++++++++++- lib/painters/tooltip_painter.dart | 33 ++++++++++++++++++++++++ lib/providers/file_notifier.dart | 1 + lib/services/file_service.dart | 7 +++++ 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 lib/painters/tooltip_painter.dart diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 158df24..9435e12 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -9,6 +9,7 @@ import 'package:odin/painters/done_icon_painter.dart'; import 'package:odin/painters/drop_icon_painter.dart'; import 'package:odin/painters/odin_logo_painter.dart'; import 'package:odin/painters/ripple_painter.dart'; +import 'package:odin/painters/tooltip_painter.dart'; import 'package:odin/providers/file_notifier.dart'; import 'package:odin/widgets/window_top_bar.dart'; import 'package:provider/provider.dart'; @@ -46,7 +47,7 @@ class _HomePageState extends State ), )..addListener(() { setState(() { - if (controller.value >= 0.9) { + if (controller.value >= 0.7) { glow = false; } else if (controller.value <= 0.1) { glow = true; @@ -118,6 +119,46 @@ class _HomePageState extends State : OdinLogoCustomPainter(), ), ), + // Tooltip painter + Align( + alignment: Alignment.center, + child: AnimatedContainer( + duration: const Duration(milliseconds: 1500), + curve: Curves.elasticOut, + margin: EdgeInsets.only( + bottom: glow + ? MediaQuery.of(context).size.width / 3 + : MediaQuery.of(context).size.width / 3.2), + width: _fileNotifier.processing + ? 160 + : _fileNotifier.loading + ? 160 + : 220, + height: 55, + child: CustomPaint( + size: Size(220, (55 * 1).toDouble()), + painter: TooltipCustomPainter(), + child: Center( + child: Padding( + padding: const EdgeInsets.only(bottom: 6.0), + child: Text( + _fileNotifier.processing + ? "Processing." + : _fileNotifier.loading + ? "Uploading." + : 'Drop files to start.', + textAlign: TextAlign.center, + style: GoogleFonts.poppins( + fontSize: 16, + fontWeight: FontWeight.bold, + color: const Color(0xFF7D5DEC), + ), + ), + ), + ), + ), + ), + ), // Drag & drop target DropTarget( onDragDone: (detail) async { diff --git a/lib/painters/tooltip_painter.dart b/lib/painters/tooltip_painter.dart new file mode 100644 index 0000000..5a5af24 --- /dev/null +++ b/lib/painters/tooltip_painter.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; + +class TooltipCustomPainter extends CustomPainter { + @override + void paint(Canvas canvas, Size size) { + Paint paint0Fill = Paint()..style = PaintingStyle.fill; + paint0Fill.color = Colors.white.withOpacity(1.0); + canvas.drawRRect( + RRect.fromRectAndCorners( + Rect.fromLTWH(0, 0, size.width, size.height * 0.8833333), + bottomRight: Radius.circular(size.width * 0.05031447), + bottomLeft: Radius.circular(size.width * 0.05031447), + topLeft: Radius.circular(size.width * 0.05031447), + topRight: Radius.circular(size.width * 0.05031447)), + paint0Fill); + + Path path_1 = Path(); + path_1.moveTo(size.width * 0.5000000, size.height); + path_1.lineTo(size.width * 0.4409937, size.height * 0.5937500); + path_1.lineTo(size.width * 0.5590063, size.height * 0.5937500); + path_1.lineTo(size.width * 0.5000000, size.height); + path_1.close(); + + Paint paint1Fill = Paint()..style = PaintingStyle.fill; + paint1Fill.color = Colors.white.withOpacity(1.0); + canvas.drawPath(path_1, paint1Fill); + } + + @override + bool shouldRepaint(covariant CustomPainter oldDelegate) { + return true; + } +} diff --git a/lib/providers/file_notifier.dart b/lib/providers/file_notifier.dart index 1e3fbb7..778d14c 100644 --- a/lib/providers/file_notifier.dart +++ b/lib/providers/file_notifier.dart @@ -5,6 +5,7 @@ import 'package:odin/services/locator.dart'; class FileNotifier with ChangeNotifier { final _fileService = locator(); bool get loading => _fileService.loading; + bool get processing => _fileService.processing; String? get fileLink => _fileService.fileLink; Future getLinkFromFilePicker() async { diff --git a/lib/services/file_service.dart b/lib/services/file_service.dart index c4cb099..873abba 100644 --- a/lib/services/file_service.dart +++ b/lib/services/file_service.dart @@ -9,16 +9,20 @@ class FileService { final _githubService = locator(); final _zipService = locator(); bool loading = false; + bool processing = false; String? fileLink; Future getLinkFromFilePicker() async { + fileLink = null; FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true); final String? _path; if (result != null) { loading = true; + processing = true; List files = result.paths.map((path) => File(path!)).toList(); final zippedFile = await _zipService.zipFile(fileToZips: files); + processing = false; _path = await _githubService.uploadFileAnonymous(zippedFile); loading = false; } else { @@ -29,12 +33,15 @@ class FileService { } Future getLinkFromDroppedFiles(List urls) async { + fileLink = null; final String? _path; if (urls.isNotEmpty) { loading = true; + processing = true; final List fileToZips = urls.map((e) => File(e.toFilePath())).toList(); final zippedFile = await _zipService.zipFile(fileToZips: fileToZips); + processing = false; _path = await _githubService.uploadFileAnonymous(zippedFile); loading = false; } else {