From fd0f27b283289e5ca0e03dbbd6c42ec86c520655 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 1 Sep 2023 08:33:07 -0700 Subject: [PATCH] 0.10.1 fixes - part 1 (#1788) * Use alternative method to determine user computer's IP Close #1733 * Fix Cavas.Text drawing Fix #1783 --- package/lib/src/controls/canvas.dart | 13 +++++++++---- .../packages/flet-runtime/src/flet_runtime/utils.py | 11 +++++++++++ .../packages/flet/src/flet/cli/commands/run.py | 10 +++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package/lib/src/controls/canvas.dart b/package/lib/src/controls/canvas.dart index 3fca82ebc..411662fe4 100644 --- a/package/lib/src/controls/canvas.dart +++ b/package/lib/src/controls/canvas.dart @@ -61,6 +61,7 @@ class _CanvasControlState extends State { var paint = CustomPaint( painter: FletCustomPainter( + context: context, theme: Theme.of(context), shapes: viewModel.shapes, onPaintCallback: (size) { @@ -94,12 +95,14 @@ class _CanvasControlState extends State { } class FletCustomPainter extends CustomPainter { + final BuildContext context; final ThemeData theme; final List shapes; final CanvasControlOnPaintCallback onPaintCallback; const FletCustomPainter( - {required this.theme, + {required this.context, + required this.theme, required this.shapes, required this.onPaintCallback}); @@ -131,7 +134,7 @@ class FletCustomPainter extends CustomPainter { } else if (shape.control.type == "shadow") { drawShadow(canvas, shape); } else if (shape.control.type == "text") { - drawText(canvas, shape); + drawText(context, canvas, shape); } } } @@ -236,7 +239,8 @@ class FletCustomPainter extends CustomPainter { paint); } - void drawText(Canvas canvas, ControlTreeViewModel shape) { + void drawText( + BuildContext context, Canvas canvas, ControlTreeViewModel shape) { var offset = Offset(shape.control.attrDouble("x")!, shape.control.attrDouble("y")!); var alignment = @@ -266,7 +270,8 @@ class FletCustomPainter extends CustomPainter { text: span, textAlign: textAlign ?? TextAlign.start, maxLines: maxLines, - ellipsis: ellipsis); + ellipsis: ellipsis, + textDirection: Directionality.of(context)); textPainter.layout(maxWidth: maxWidth ?? double.infinity); var angle = shape.control.attrDouble("rotate", 0)!; diff --git a/sdk/python/packages/flet-runtime/src/flet_runtime/utils.py b/sdk/python/packages/flet-runtime/src/flet_runtime/utils.py index ed4eef859..6bab0a8ef 100644 --- a/sdk/python/packages/flet-runtime/src/flet_runtime/utils.py +++ b/sdk/python/packages/flet-runtime/src/flet_runtime/utils.py @@ -147,6 +147,17 @@ def get_free_tcp_port(): return sock.getsockname()[1] +def get_local_ip(): + try: + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.connect(("8.8.8.8", 80)) + local_ip = s.getsockname()[0] + return local_ip + except Exception as e: + hostname = socket.gethostname() + return socket.gethostbyname(hostname) + + def get_current_script_dir(): pathname = os.path.dirname(sys.argv[0]) return os.path.abspath(pathname) diff --git a/sdk/python/packages/flet/src/flet/cli/commands/run.py b/sdk/python/packages/flet/src/flet/cli/commands/run.py index 69c1aea12..11f478e6c 100644 --- a/sdk/python/packages/flet/src/flet/cli/commands/run.py +++ b/sdk/python/packages/flet/src/flet/cli/commands/run.py @@ -15,7 +15,12 @@ from flet.cli.commands.base import BaseCommand from flet_core.utils import random_string from flet_runtime.app import close_flet_view, open_flet_view -from flet_runtime.utils import get_free_tcp_port, is_windows, open_in_browser +from flet_runtime.utils import ( + get_free_tcp_port, + get_local_ip, + is_windows, + open_in_browser, +) from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer @@ -293,8 +298,7 @@ def restart_program(self): def print_qr_code(self, orig_url: str, android: bool): u = urlparse(orig_url) - hostname = socket.gethostname() - ip_addr = socket.gethostbyname(hostname) + ip_addr = get_local_ip() lan_url = urlunparse( (u.scheme, f"{ip_addr}:{u.port}", u.path, None, None, None) )