I am making my first app with Flet in python. The problem that I get, is when I build the app as an apk, it is just blank inside. No error, no crash. The weirdest thing is, that the app works completely fine when testing. I've seen some people experiencing the same issue on the internet, but their solutions didn't work for me.
I build the app with flet build apk -vv
A little bit about the app:
- I made the app for me and my friends' made up language.
- Some parts of the code are in russian.
- It imports only requests and flet itself.
- It has GET and PUT requests.
- It has a few UI elements. (Input Fields, Buttons, Labels)
Versions of stuff:
- python: 3.12
- flet: 0.28.3
- flutter: 3.29.2
main.py:
import flet as ft
import process_data as pd
import requests
URL = "https://json.extendsclass.com/bin/"
def get_data() -> dict | str:
res_get = requests.get(URL)
if res_get.status_code == 200:
return res_get.json()
else:
return res_get.text
def append(ru, wtml):
"""
:param ru: - in russian
:param wtml: - in watermelonian
"""
new_data = get_data()
new_data[ru] = wtml
res_update = requests.put(URL, json=new_data, headers={"Security-key": ""})
if res_update.status_code == 200:
return res_update.json()
else:
return res_update.text
def change(ru, wtml):
append(ru, wtml)
translations = get_data()
VALID_PUNCTUATION = ". , ! ? ; : @ # $ % ^ & / * - + ~".split(" ")
def main(page: ft.Page):
def translate(e):
to_translate = input_field.value.lower()
to_translate = ''.join(char for char in to_translate if char not in VALID_PUNCTUATION)
to_translate = to_translate.split(" ")
result = ""
for word in to_translate:
if word in translations:
result += translations[word]
else:
if pd.check_word_already_good(word):
result += word
else:
result += "ар"+word+"уз"
result += " "
result = pd.copy_capitalization(input_field.value, result)
result = pd.copy_punctuation(input_field.value, result)
output_field.value = result
page.update()
input_field = ft.TextField(label="Русский", hint_text="Введите текст сюда")
output_field = ft.TextField(label="Арбузный", read_only=True, value="Жмакни на кнопку")
submit_button = ft.Button(text="Перевести", on_click=translate)
page.add(ft.Container(
content=ft.Column(
controls=(input_field, output_field, submit_button)
), margin=ft.margin.only(10, 110, 10, 100)))
def add_word(e):
append(new_word_field.value.lower(), new_word_translation_field.value.lower())
translations[new_word_field.value.lower()] = new_word_translation_field.value.lower()
new_word_text.value = f"Добавлено слово \"{new_word_field.value}\" -> \"{new_word_translation_field.value}\""
page.update()
new_word_field = ft.TextField(label="Добавить слово (Русский)", hint_text="Введите текст сюда")
new_word_translation_field = ft.TextField(label="Перевод (Арбузный)", hint_text="Введите текст сюда")
submit_new_word_button = ft.Button(text="Добавить", on_click=add_word)
new_word_text = ft.Text(value="")
page.add(ft.Container(
content=ft.Column(
controls=(new_word_field, new_word_translation_field, submit_new_word_button, new_word_text)
), margin=ft.margin.only(10, 10, 10, 110)))
page.update()
ft.app(main, port=5000)
process_data.py:
def apply_spaces_patterned(pattern, text):
result = []
text_index = 0
for char in pattern:
if char == " ":
result.append(" ")
else:
if text_index < len(text):
result.append(text[text_index])
text_index += 1
if text_index < len(text):
result.append(text[text_index:])
return "".join(result)
def copy_capitalization(input_str: str, output_str: str):
words = input_str.split(" ")
output_words = output_str.split(" ")
for i, word in enumerate(words):
if word[0].capitalize() == word[0]:
# is capitalized
if word.upper() == word:
# is caps
try:
output_words[i] = output_words[i].upper()
except IndexError:
print("out of range, but it's fine bro")
else:
try:
output_words[i] = output_words[i][0].upper() + output_words[i][1:]
except IndexError:
print("out of range, but it's fine bro")
result = "".join(output_words)
return apply_spaces_patterned(output_str, result)
def copy_punctuation(pattern: str, text: str):
VALID_PUNCTUATION = ". , ! ? ; : @ # $ % ^ & / * - + ~".split(" ")
punctuations = []
pattern_words = pattern.split(" ")
text_words = text.split(" ")
for i, word in enumerate(pattern_words):
if word[-1] in VALID_PUNCTUATION:
punctuations.append([word[-1], i])
result = ""
if not punctuations:
return text
for i, word in enumerate(text_words):
added = False
for punc in punctuations:
if punc[1] == i:
added = True
result = result + str(text_words[punc[1]] + punc[0]) + " " # лучше это не трогать
break
if not added:
result = result + word + " "
if result[-1] == " ":
result = result[0:len(result)-1]
return result
def check_word_already_good(word):
allowed_letters = "а р б у з".split(" ")
for letter in word:
if letter not in allowed_letters:
return False
return True
Any help is appreciated!
Things I've tried:
- Putting the exact Flet version in requirements.txt
- Reinstalling flutter
- Rebuilding
What I expect: app on Android that has a UI, and works.