Skip to content

Commit

Permalink
add tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Nov 15, 2021
1 parent e3c2f6d commit 471ee77
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
43 changes: 42 additions & 1 deletion lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -46,7 +47,7 @@ class _HomePageState extends State<HomePage>
),
)..addListener(() {
setState(() {
if (controller.value >= 0.9) {
if (controller.value >= 0.7) {
glow = false;
} else if (controller.value <= 0.1) {
glow = true;
Expand Down Expand Up @@ -118,6 +119,46 @@ class _HomePageState extends State<HomePage>
: 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 {
Expand Down
33 changes: 33 additions & 0 deletions lib/painters/tooltip_painter.dart
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions lib/providers/file_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:odin/services/locator.dart';
class FileNotifier with ChangeNotifier {
final _fileService = locator<FileService>();
bool get loading => _fileService.loading;
bool get processing => _fileService.processing;
String? get fileLink => _fileService.fileLink;

Future<void> getLinkFromFilePicker() async {
Expand Down
7 changes: 7 additions & 0 deletions lib/services/file_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ class FileService {
final _githubService = locator<GithubService>();
final _zipService = locator<ZipService>();
bool loading = false;
bool processing = false;
String? fileLink;

Future<void> getLinkFromFilePicker() async {
fileLink = null;
FilePickerResult? result =
await FilePicker.platform.pickFiles(allowMultiple: true);
final String? _path;
if (result != null) {
loading = true;
processing = true;
List<File> 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 {
Expand All @@ -29,12 +33,15 @@ class FileService {
}

Future<void> getLinkFromDroppedFiles(List<Uri> urls) async {
fileLink = null;
final String? _path;
if (urls.isNotEmpty) {
loading = true;
processing = true;
final List<File> 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 {
Expand Down

0 comments on commit 471ee77

Please sign in to comment.