Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.10.1 fixes - part 1 #1788

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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