Skip to content

Commit

Permalink
0.10.1 fixes - part 1 (#1788)
Browse files Browse the repository at this point in the history
* Use alternative method to determine user computer's IP

Close #1733

* Fix Cavas.Text drawing

Fix #1783
  • Loading branch information
FeodorFitsner authored Sep 1, 2023
1 parent 66e4ddb commit fd0f27b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
13 changes: 9 additions & 4 deletions package/lib/src/controls/canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class _CanvasControlState extends State<CanvasControl> {

var paint = CustomPaint(
painter: FletCustomPainter(
context: context,
theme: Theme.of(context),
shapes: viewModel.shapes,
onPaintCallback: (size) {
Expand Down Expand Up @@ -94,12 +95,14 @@ class _CanvasControlState extends State<CanvasControl> {
}

class FletCustomPainter extends CustomPainter {
final BuildContext context;
final ThemeData theme;
final List<ControlTreeViewModel> shapes;
final CanvasControlOnPaintCallback onPaintCallback;

const FletCustomPainter(
{required this.theme,
{required this.context,
required this.theme,
required this.shapes,
required this.onPaintCallback});

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)!;
Expand Down
11 changes: 11 additions & 0 deletions sdk/python/packages/flet-runtime/src/flet_runtime/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions sdk/python/packages/flet/src/flet/cli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
)
Expand Down

0 comments on commit fd0f27b

Please sign in to comment.