Problem with flet.app port
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17k
- Forks
- 694
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 33
Description
Hi this is my code main.py
import flet as ft
from views.Login import loginview
from views.Register import registerview
from views.Home import homeview
from views.MapView import mapview
from library.toast import Toast
import httpx
from tempfile import mkdtemp
from pathlib import Path
import sqlite3
import socket
import requests
from library.firebase import Firebase
def main(page: ft.Page):
page.title = "my navigation apps"
# Geolocate IP API
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
response = requests.get("https://api.ipfind.com/?ip="+ip).json()
print(response)
s.close()
# write file
#dest1 = Path(mkdtemp()) / Path("Chinook_Sqlite.sqlite")
#url1 = "https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite"
#response1 = urllib.request.urlopen(url1)
#print(response1)
# Initialize the Firebase class with the provided credentials
firebase = Firebase("IuGbhgJJoTNSURmB8DBjWIpMgPiSq85SQ8rubWbw", "https://fir-db-63961.firebaseio.com/users/")
'''obj = {
"name": nom,
"surname": prenom,
"adresse": adresse,
"phone": phone,
"birthday": birthday,
"synopsis": synopsis,
"login": login,
"password": password,
"email": email
}'''
# dataresult = firebase.delete_data("56")
# print (dataresult)
# autoclass('java.lang.System').out.println('Hello world')
# API Call Json format
with httpx.Client() as client:
response = client.get("https://jsonplaceholder.typicode.com/posts/42")
payload = response.json()
print(payload['body'])
# SQLITE3
dest = Path(mkdtemp()) / Path("Chinook_Sqlite.sqlite")
con = sqlite3.connect(dest)
cur = con.cursor()
cur.execute('''
CREATE TABLE User (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
surname TEXT NOT NULL,
birthday DATE NOT NULL,
address TEXT NOT NULL,
email TEXT NOT NULL,
zipcode TEXT NOT NULL,
phonenumber TEXT NOT NULL,
country TEXT NOT NULL,
login TEXT NOT NULL,
password TEXT NOT NULL
);
''')
try:
cur.execute('SELECT COUNT(*) FROM User;')
result = cur.fetchone()[0]
print(f'La table User existe et contient {result} ligne(s).')
insert_data = ('John', 'Doe', '1990-01-01', '123 Main St', 'john@example.com', '12345', '555-1234', 'USA', 'johndoe', 'password')
cur.execute('''
INSERT INTO User (name, surname, birthday, address, email, zipcode, phonenumber, country, login, password)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
''', insert_data)
con.commit()
except sqlite3.OperationalError:
print('La table User n\'existe pas.')
try:
cur.execute('SELECT COUNT(*) FROM User;')
result = cur.fetchone()[0]
print(f'La table User existe et contient {result} ligne(s).')
except sqlite3.OperationalError:
print('La table User n\'existe pas.')
def route_change(route):
page.views.clear()
loginview(page)
if page.route == "/register":
# registerview UI
registerview(page)
if page.route == "/home":
# homeview UI
homeview(page)
if page.route == "/maps":
# mapview UI
mapview(page)
page.update()
def view_pop(view):
page.views.pop()
top_view = page.views[-1]
page.go(top_view.route)
page.on_route_change = route_change
page.on_view_pop = view_pop
page.go(page.route)
ft.app(target=main, assets_dir="assets")
and this is the code of login.py
import flet as ft
from pathlib import Path
from tempfile import mkdtemp
from flet.auth.providers import GitHubOAuthProvider
from flet.auth.providers import Auth0OAuthProvider
def loginview(page):
# Create a temporary file
temporary_directory = Path(mkdtemp())
GITHUB_CLIENT_ID = "Ov23lihy0qLzb4Vf3NGk"
GITHUB_CLIENT_SECRET = "4c2a35e33dd3df107a2638c6d15331320ce1d266"
provider = GitHubOAuthProvider(
client_id=GITHUB_CLIENT_ID,
client_secret=GITHUB_CLIENT_SECRET,
redirect_url="http://localhost:8550/oauth_callback",
)
Auth0_CLIENT_ID = "I84tpGtujC37deUPGNR42LzrznQpFzkm"
Auth0_CLIENT_SECRET = "HhsjXZ0zYTGtK-WwIKR_3pkGZ7sNx6W7JgwUIc1vl_2lIdjz57aIKE0jh6hpfdY2"
providerFb = Auth0OAuthProvider(
domain="dev-nwy7rv0qbeuc63ys.us.auth0.com",
client_id=Auth0_CLIENT_ID,
client_secret=Auth0_CLIENT_SECRET,
redirect_url="http://localhost:8550/api/oauth/redirect",
)
page.views.append(
ft.View(
"/",
[
ft.SafeArea(
ft.Row(
[
ft.Image(src="https://th.bing.com/th/id/OIP.hUGALAXd59AOY9oKSqFbbwHaHT?rs=1&pid=ImgDetMai",width=200,height=200,fit=ft.ImageFit.CONTAIN,),
],
alignment=ft.MainAxisAlignment.CENTER,
spacing=0,
)
),
ft.SafeArea(
ft.Row(
[
ft.Column(
[
ft.TextField(icon=ft.icons.SUPERVISED_USER_CIRCLE_OUTLINED, label="Login", border=ft.InputBorder.UNDERLINE, keyboard_type=ft.KeyboardType.TEXT),
ft.TextField(icon=ft.icons.PASSWORD_ROUNDED, label="Password", border=ft.InputBorder.UNDERLINE, password=True, keyboard_type=ft.KeyboardType.TEXT),
]
)
],
alignment=ft.MainAxisAlignment.CENTER,
spacing=0,
)
),
ft.SafeArea(
ft.Row(
[
ft.Column(
[
ft.ElevatedButton(content=ft.Text("Log In"),bgcolor='#ff0000', color='#ffffff',width=270,on_click=lambda _: showSnackbar(page)),
ft.ElevatedButton("Connect with Github",icon_color="white",width=270,bgcolor='#000000',color='#ffffff',on_click=lambda _: githublogin(page)),
ft.ElevatedButton("Connect Auth0/Facebook",icon="facebook",icon_color="white",width=270,bgcolor='#3b5998',color='#ffffff',on_click=lambda _: auth0login(page)),
],
alignment=ft.MainAxisAlignment.CENTER,
spacing=0,
)
],
alignment=ft.MainAxisAlignment.CENTER,
spacing=0,
)
),
ft.FloatingActionButton(icon=ft.icons.ADD, bgcolor=ft.colors.LIME_300, on_click=lambda _: page.go("/register"))
],
)
)
def store_data(value):
print("Session Storage ::::::::: Créer un répertoire de stockage temporaire")
dest = temporary_directory / Path("bee-sessionstorage.txt")
dest.write_bytes(value.encode())
def read_data():
print("Session Storage ::::::::: lire un répertoire de stockage temporaire")
dest = temporary_directory / Path("bee-sessionstorage.txt")
if dest.exists():
with open(dest, "rb") as f:
data = f.read().decode()
print(data)
return data
else:
return None
def showSnackbar(page):
store_data("valusqdqsdsqe")
page.snack_bar = ft.SnackBar(ft.Text("Hello"))
page.snack_bar.open = True
page.update()
read_data()
def githublogin(page):
page.login(provider)
def auth0login(page):
page.login(providerFb)
def on_login(e):
print("Login error:", e.error)
print("Access token:", page.auth.token.access_token)
print("User ID:", page.auth.user.id)
page.on_login = on_login
my problem is with ft.app(target=main, assets_dir="assets") to us GitHubOAuthProvider or Auth0OAuthProvider i do add specifi port to flet.app like this
ft.app(target=main, assets_dir="assets", port=8550)
but when i add the port parameter the application start on android with blank screen i have only blank screen but when i remove the port parameter the application start normaly but GitHubOAuthProvider or Auth0OAuthProvider does not work
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the Android blank screen using main.py with ft.app and the port argument, then compare it with the working configuration without the port. Read login.py alongside the GitHubOAuthProvider and Auth0OAuthProvider setup; done means the Android app renders normally and the OAuth login flows work with the required port.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- authentication, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100