from typing import Optional


def filter_dictionary(dictionary: dict, fields_to_keep: Optional[tuple], sort_by_field_list: bool = False) -> dict:
    """
    Filters a dictionary and keeps only the keys that appears in the given list
    :param dictionary: the origin dict
    :param fields_to_keep: the list which contains the wanted keys
    :param sort_by_field_list: whether to sort the dictionary keys according to the field list
    :return: the dictionary, with only fields that appeared in fields_to_keep.
    >>> filter_dictionary({1:2,3:4}, (3,))
    {3: 4}
    >>> filter_dictionary({1:2,3:4}, (3,1))
    {1: 2, 3: 4}
    >>> filter_dictionary({1:2,3:4}, (3,1), True)
    {3: 4, 1: 2}
    >>> filter_dictionary({1:2,3:4}, (,), True)
    {}
    >>> filter_dictionary({1:2,3:4}, None)
    {}
    """
    filtered = {k: v for k, v in dictionary.items() if k in (fields_to_keep or [])}

    if sort_by_field_list:
        key_order = {v: i for i, v in enumerate(fields_to_keep or [])}
        filtered = dict(sorted(filtered.items(), key=lambda pair: key_order[pair[0]]))

    return filtered