'Is there a recommended way to use models and common files in multiple flutter projects?

I have two flutter projects, one is admin application and other user application. Both applications use many same models and classes, and common widgets.

Currently I am copying the model classes and widgets, to both projects, and when I need to change anything, I need to remember to change it in the other project too.

Is there any other method to do this? Should I create a custom package and import it in both projects? What would be the recommended way to do this?



Solution 1:[1]

The website loads the search results using ajax. It also checks the headers and cookies being sent with the request. See a sample scrapy spider where I have sent the specific headers required. Scrapy will handle the cookies automatically.

import scrapy

class PostalSpider(scrapy.Spider):
    name = 'postal'
    allowed_domains = ['postal-code.co.uk']
    start_urls = ['https://postal-code.co.uk']

    custom_settings = {
        'USER_AGENT': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
    }

    def parse(self, response):
        headers = {
            'accept': 'application/json, text/javascript, */*; q=0.01',
            'accept-encoding': 'gzip, deflate, br',
            'accept-language': 'en-US,en;q=0.9',
            'referer': 'https://postal-code.co.uk/',
            'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="97", "Chromium";v="97"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Linux"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-origin',
            'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36',
            'x-requested-with': 'XMLHttpRequest',
        }
        yield response.follow("https://postal-code.co.uk/ajax/search.php?word=Edward+Avenue,+Camberley,+Surrey,+GU15&geocodeProvider=1", 
            callback=self.parse_results, headers=headers)

    def parse_results(self, response):
        for result in response.json():
            yield result

Sample screenshot of the spider run Spider run sample

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 msenior_