Skip to content

Commit e4b473e

Browse files
Container fixes (#275)
* Fix container size inside Ink Fix #266 * All print() methods replaced with logging.info() Fix #273 * openPopupBrowserWindow()
1 parent 48d7018 commit e4b473e

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

package/lib/src/controls/container.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ class ContainerControl extends StatelessWidget {
145145
return constrainedControl(
146146
animation == null
147147
? Container(
148+
width: control.attrDouble("width"),
149+
height: control.attrDouble("height"),
148150
margin: parseEdgeInsets(control, "margin"),
149151
child: ink,
150152
)
151153
: AnimatedContainer(
152154
duration: animation.duration,
153155
curve: animation.curve,
156+
width: control.attrDouble("width"),
157+
height: control.attrDouble("height"),
154158
margin: parseEdgeInsets(control, "margin"),
155159
child: ink),
156160
parent,
@@ -200,7 +204,6 @@ class ContainerControl extends StatelessWidget {
200204
}
201205
: null,
202206
child: GestureDetector(
203-
child: container,
204207
onTapDown: onClick
205208
? (details) {
206209
debugPrint("Container ${control.id} clicked!");
@@ -224,6 +227,7 @@ class ContainerControl extends StatelessWidget {
224227
eventData: "");
225228
}
226229
: null,
230+
child: container,
227231
),
228232
);
229233
}

package/lib/src/utils/platform_utils_non_web.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ bool isProgressiveWebApp() {
55
String getFletRouteUrlStrategy() {
66
return "";
77
}
8+
9+
void openPopupBrowserWindow(
10+
String url, String windowName, int minWidth, int minHeight) {}

package/lib/src/utils/platform_utils_web.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:html';
2+
import 'dart:math';
23

34
bool isProgressiveWebApp() {
45
return window.matchMedia('(display-mode: standalone)').matches ||
@@ -11,3 +12,17 @@ String getFletRouteUrlStrategy() {
1112
document.head?.querySelector("meta[name='flet-route-url-strategy']");
1213
return meta != null ? meta.attributes["content"]! : "";
1314
}
15+
16+
void openPopupBrowserWindow(
17+
String url, String windowName, int minWidth, int minHeight) {
18+
int screenWidth = window.screen!.width!;
19+
int screenHeight = window.screen!.height!;
20+
final dualScreenLeft = window.screenLeft! < 0 ? -screenWidth : 0;
21+
var toolbarHeight = window.outerHeight - window.innerHeight!;
22+
var width = max(minWidth, screenWidth - 300);
23+
var height = max(minHeight, screenHeight - 300);
24+
var left = (screenWidth / 2) - (width / 2) + dualScreenLeft;
25+
var top = (screenHeight / 2) - (height / 2) - toolbarHeight;
26+
window.open(url, windowName,
27+
"top=$top,left=$left,width=$width,height=$height,scrollbars=yes");
28+
}

sdk/python/flet/control.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,6 @@ def build_update_commands(self, index, added_controls, commands, isolated=False)
338338
hashes[hash(ctrl)] = ctrl
339339
current_ints.append(hash(ctrl))
340340

341-
# print("previous_ints:", previous_ints)
342-
# print("current_ints:", current_ints)
343-
344341
sm = SequenceMatcher(None, previous_ints, current_ints)
345342

346343
n = 0

sdk/python/flet/flet.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def page(
6464
route_url_strategy=route_url_strategy,
6565
)
6666
url_prefix = os.getenv("FLET_DISPLAY_URL_PREFIX")
67-
print("Page URL:" if url_prefix == None else url_prefix, conn.page_url)
67+
if url_prefix != None:
68+
print(url_prefix, conn.page_url)
69+
else:
70+
logging.info(f"Page URL: {conn.page_url}")
6871

6972
page = Page(conn, constants.ZERO_SESSION)
7073
conn.sessions[constants.ZERO_SESSION] = page
@@ -105,7 +108,10 @@ def app(
105108
)
106109

107110
url_prefix = os.getenv("FLET_DISPLAY_URL_PREFIX")
108-
print("App URL:" if url_prefix == None else url_prefix, conn.page_url)
111+
if url_prefix != None:
112+
print(url_prefix, conn.page_url)
113+
else:
114+
logging.info(f"App URL: {conn.page_url}")
109115

110116
terminate = threading.Event()
111117

@@ -116,7 +122,7 @@ def exit_gracefully(signum, frame):
116122
signal.signal(signal.SIGINT, exit_gracefully)
117123
signal.signal(signal.SIGTERM, exit_gracefully)
118124

119-
print("Connected to Flet app and handling user sessions...")
125+
logging.info("Connected to Flet app and handling user sessions...")
120126

121127
fvp = None
122128

@@ -198,13 +204,13 @@ def on_event(conn, e):
198204
Event(e.eventTarget, e.eventName, e.eventData)
199205
)
200206
if e.eventTarget == "page" and e.eventName == "close":
201-
print("Session closed:", e.sessionID)
207+
logging.info(f"Session closed: {e.sessionID}")
202208
del conn.sessions[e.sessionID]
203209

204210
def on_session_created(conn, session_data):
205211
page = Page(conn, session_data.sessionID)
206212
conn.sessions[session_data.sessionID] = page
207-
print("Session started:", session_data.sessionID)
213+
logging.info(f"Session started: {session_data.sessionID}")
208214
try:
209215
assert session_handler is not None
210216
session_handler(page)
@@ -463,7 +469,7 @@ def _download_fletd():
463469
temp_fletd_dir = Path(tempfile.gettempdir()).joinpath(f"fletd-{ver}")
464470

465471
if not temp_fletd_dir.exists():
466-
print(f"Downloading Fletd v{ver} to {temp_fletd_dir}")
472+
logging.info(f"Downloading Fletd v{ver} to {temp_fletd_dir}")
467473
temp_fletd_dir.mkdir(parents=True, exist_ok=True)
468474
ext = "zip" if is_windows() else "tar.gz"
469475
file_name = f"fletd-{ver}-{get_platform()}-{get_arch()}.{ext}"
@@ -492,7 +498,7 @@ def _download_fletd():
492498
def _download_flet_client(file_name):
493499
ver = version.version
494500
temp_arch = Path(tempfile.gettempdir()).joinpath(file_name)
495-
print(f"Downloading Flet v{ver} to {temp_arch}")
501+
logging.info(f"Downloading Flet v{ver} to {temp_arch}")
496502
flet_url = f"https://github.com/flet-dev/flet/releases/download/v{ver}/{file_name}"
497503
urllib.request.urlretrieve(flet_url, temp_arch)
498504
return str(temp_arch)
@@ -568,7 +574,6 @@ def print_output(self, p):
568574
break
569575
line = line.decode("utf-8").rstrip("\r\n")
570576
if line.startswith(self.page_url_prefix):
571-
# print(line)
572577
if not self.page_url:
573578
self.page_url = line[len(self.page_url_prefix) + 1 :]
574579
print(self.page_url)
@@ -655,7 +660,6 @@ def main():
655660
port = args.port
656661
if args.port == None:
657662
port = _get_free_tcp_port()
658-
# print("port:", port)
659663

660664
my_event_handler = Handler(
661665
[sys.executable, "-u", script_path],
@@ -674,7 +678,7 @@ def main():
674678
if my_event_handler.terminate.wait(1):
675679
break
676680
except KeyboardInterrupt:
677-
pass # print("Keyboard interrupt!")
681+
pass
678682

679683
if my_event_handler.fvp != None and not is_windows():
680684
try:

0 commit comments

Comments
 (0)