1568264366
Originally published by Rishi Banerjee at https://medium.com
It was a frustrating task to make a search feature inside a flutter application, given the search target was a collection in firebase. Imagine that collection growing and stacking on top of each other to make a list of collections that you need to search through. For example, you are making a social media service for your next big startup that is gonna revolutionize the human lifestyle. But wait, you are sitting there, trying to figure out, how are you gonna make a user search for the girl he was in his class with? He will probably search for the school name, city name, first name, last name or maybe the phone number he got access to from a shady but distant friend in class. Okay, got the logic, but HOW?
We’ve all been through the basics of Linear Search and Binary Search. Fairly basic approach of iterating over a list of items in a fancy way and locating its index. Done. But how do we search through a set of documents inside a collection. One of the YouTubers, Raja Yogan made an excellent video on how to implement instant search using flutter and firebase here.
If you go through the code and see, it is fairly ‘simple’ for a simple search. What happens when the database scales? Are you gonna redundantly write code for different database tables? No. This is one of the reasons I stopped using firebase for bigger projects and switched to writing code for a custom backend. More on that topic later.
API’s allow you to dynamically search through databases quickly and find custom patterns instead of hard coded expressions. Too much? Well wait, will show you guys how to make one yourself in a few minutes.
Ah, the most mundane task of all. Setting up the Django template project. I’m skipping the parts of installing Python 3.7 and Django 2.2, because if you made it to this blog, it means you have some intermediate understanding of both Django and flutter.
Let’s focus on creating the app inside your template project.
python manage.py startapp search
This will create a boilerpate Django app inside your project. Hurray?
Lets create a model, which will basically translate to a SQL database behind the scenes.
Category and Food model that we are gonna search through.
We are done with making the database.
Run the migration commands and create the super user to access the web admin panel. On accessing the localhost:8000/admin url you should see something like this, given you registered the models in admin.py
localhost:8000/admin
Great, now go ahead and add some amazing Food Items and Categories for the former to fall under.
Now the most gruesome part, making the API.
We are going to use DRF (Django Rest Framework) which makes life a lot easier by handling some of the burden we carry all day long.
Be generous and add ‘rest_framework’ to your settings.py
We need to work on three more files, views.py, serializers.py and urls.py. Writing the serializer part is simpler, so lets do that first.
Read more about serializers here.
Now comes the view part. Writing a view that enables search filter. A simple view first.
views.py
DRF has inbuilt search functionality and database features which allows you to do scalable searching.
Inside your app’s urls.py, add the following:
urlpatterns = [ path('foods/', views.FoodAPIView.as_view()), ]
Open your browser and go to this url localhost:8000/api/foods/
The API View doing the job of displaying JSON content
The FoodAPIView in our views.py file enables us to see the data and make api requests to the specified url.
The Django REST framework has some inbuilt utilities that allow you to implement search easily. Though underneath it also uses i_contains in some cases, it is fast, scalable and easy to implement ;)
Add the following line inside the class FoodAPIView.
search_fields = [‘name’, ‘price’]
On doing so the class would look something like this
The searchfields parameter and the filterbackends are the only things you need to add.
We are adding the search_field in API view to specify which columns should the service look for when searching for a query.
Should we now test the search query?
localhost:8000/api/foods?search=Tando
This should return the search results that match the query.
Searching for Tando
So it works. WOW! Not a big deal really. This was the easy part. Now we need to integrate it with the mobile app.
The easy part? Nah this is heavily inspired by what I saw in Raja Yogan’s code.
Well, this code is really modular and you can find the entire code for reference here.
I guess setting up a sample flutter app wont be an issue and that is the reason I’m skipping the utterly difficult task
Let’s write the main.dart file first.
SearchPage() coming soon!
This is how I usually kickstart the app. Dividing the app into small components.
Now let’s code up the search page.
Long code? Find it here.
On running this much of the app, we should see something like this.
Simple UI for Search
Without hosting the Django app in a cloud service like AWS or GCP, we need to call the API’s. To do so first we need to connect both the devices [the computer that you are using and the phone that you are running the app on] to the same network.
You need to find the IP address your devices are connected to.
Use ifconfig for Ubuntu, ip addr in Arch and ifconfig in windows to get the IP address.
As of now, the server was running on localhost:8000/
Our app running on the phone cannot access it. Once we have the ip in hand we need to change a line in settings.py. Replace ALLOWED_HOSTS inside the Django settings.py file with this.
ALLOWED_HOSTS = ['192.168.43.129', 'localhost', '127.0.0.1']
Now turn off the Django server, and restart it with the following command.
python manage.py runserver 0.0.0.0:8000
This will allow you to access your django api in the following URL
http://192.168.43.***:8000/api/foods/
The IP must be different in your case.
Great, we have written a great amount of code by now. Time to write the functioning.
search_service.dart
Here we have a static function aptly named searchDjangoApi which returns a Future<String>. The URL is the one that we just started accessing our django app at. We are getting the ‘query’ parameter from the UI class and passing it to the function here. Which is then passed as the URL search parameter. The http.Response object helps us retrieve the data that we expect to have. Once we have the response, we return its body.
Woah! Done. Now run your flutter app and the django server.
Let’s see what we get when we search for ‘tan’
Results built inside the ListView.builder class
That’s it. There is our flutter and django code working together to make this world a better place. Dynamic search is also there, but I’m keeping it out of the scope of this blog. Peace.
If you need the code, just visit my GitHub profile here.
I am a noob programmer and this entire code structure was figured out by me and a few fellow programmers.
Thanks for reading ❤
If you liked this post, share it with all of your programming buddies!
Follow us on Facebook | Twitter
☞ Flutter: Adding Bluetooth Functionality
☞ Build Your First Python and Django Application
☞ Creating a Simple ToDo Api With Django
#django #flutter #rest #api
1568265389
Wich implementation of JWT do you recommend?
1597014000
Flutter Google cross-platform UI framework has released a new version 1.20 stable.
Flutter is Google’s UI framework to make apps for Android, iOS, Web, Windows, Mac, Linux, and Fuchsia OS. Since the last 2 years, the flutter Framework has already achieved popularity among mobile developers to develop Android and iOS apps. In the last few releases, Flutter also added the support of making web applications and desktop applications.
Last month they introduced the support of the Linux desktop app that can be distributed through Canonical Snap Store(Snapcraft), this enables the developers to publish there Linux desktop app for their users and publish on Snap Store. If you want to learn how to Publish Flutter Desktop app in Snap Store that here is the tutorial.
Flutter 1.20 Framework is built on Google’s made Dart programming language that is a cross-platform language providing native performance, new UI widgets, and other more features for the developer usage.
Here are the few key points of this release:
In this release, they have got multiple performance improvements in the Dart language itself. A new improvement is to reduce the app size in the release versions of the app. Another performance improvement is to reduce junk in the display of app animation by using the warm-up phase.
If your app is junk information during the first run then the Skia Shading Language shader provides for pre-compilation as part of your app’s build. This can speed it up by more than 2x.
Added a better support of mouse cursors for web and desktop flutter app,. Now many widgets will show cursor on top of them or you can specify the type of supported cursor you want.
Autofill was already supported in native applications now its been added to the Flutter SDK. Now prefilled information stored by your OS can be used for autofill in the application. This feature will be available soon on the flutter web.
A new widget for interaction
InteractiveViewer
is a new widget design for common interactions in your app like pan, zoom drag and drop for resizing the widget. Informations on this you can check more on this API documentation where you can try this widget on the DartPad. In this release, drag-drop has more features added like you can know precisely where the drop happened and get the position.
In this new release, there are many pre-existing widgets that were updated to match the latest material guidelines, these updates include better interaction with Slider
and RangeSlider
, DatePicker
with support for date range and time picker with the new style.
pubspec.yaml
formatOther than these widget updates there is some update within the project also like in pubspec.yaml
file format. If you are a flutter plugin publisher then your old pubspec.yaml
is no longer supported to publish a plugin as the older format does not specify for which platform plugin you are making. All existing plugin will continue to work with flutter apps but you should make a plugin update as soon as possible.
Visual Studio code flutter extension got an update in this release. You get a preview of new features where you can analyze that Dev tools in your coding workspace. Enable this feature in your vs code by _dart.previewEmbeddedDevTools_
setting. Dart DevTools menu you can choose your favorite page embed on your code workspace.
The updated the Dev tools comes with the network page that enables network profiling. You can track the timings and other information like status and content type of your** network calls** within your app. You can also monitor gRPC traffic.
Pigeon is a command-line tool that will generate types of safe platform channels without adding additional dependencies. With this instead of manually matching method strings on platform channel and serializing arguments, you can invoke native class and pass nonprimitive data objects by directly calling the Dart
method.
There is still a long list of updates in the new version of Flutter 1.2 that we cannot cover in this blog. You can get more details you can visit the official site to know more. Also, you can subscribe to the Navoki newsletter to get updates on these features and upcoming new updates and lessons. In upcoming new versions, we might see more new features and improvements.
You can get more free Flutter tutorials you can follow these courses:
#dart #developers #flutter #app developed #dart devtools in visual studio code #firebase local emulator suite in flutter #flutter autofill #flutter date picker #flutter desktop linux app build and publish on snapcraft store #flutter pigeon #flutter range slider #flutter slider #flutter time picker #flutter tutorial #flutter widget #google flutter #linux #navoki #pubspec format #setup flutter desktop on windows
1622532470
Hire Flutter App Developers: WebClues Infotech is a Flutter App Development company. Our Flutter mobile app development team can create cross-platform apps for different industry verticals. Our Flutter developers will help you extend your business’s scope by developing enhanced functionality and a feature-rich app. To provide a rich user experience to your users, hire dedicated Flutter app developers from WebClues Infotech today!
#hire flutter app developers #hire dedicated flutter app developer usa #hire flutter app developer usa #hire dedicated flutter app developer #hire flutter developer #flutter app development company
1606986883
Are you looking for the best flutter app development company? Then AppClues Infotech is the leading flutter app development company in USA offering the best service worldwide. We focused on developing hybrid mobile apps on Android & iOS and assures our end-user about exceptional and functionally-rich mobile apps.
For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910
#top flutter app development company in usa #best flutter app development service #best flutter app development company #hire flutter app developers #flutter app development company #expert flutter app development company
1608627556
AppClues Infotech is one of the best flutter app development company in USA & India. Our diverse and experienced team of developers can help you sketch the smartest and quickest solution for your mobile app development projects with the most superior technology.
For more info:
Website: https://www.appcluesinfotech.com/
Email: info@appcluesinfotech.com
Call: +1-978-309-9910
#top flutter app development company in usa #best flutter app development service #best flutter app development company #hire flutter app developers #flutter app development company in usa & india #custom flutter app development service
1644991598
The Ultimate Guide To Tik Tok Clone App With Firebase - Ep 2
In this video, I'm going to show you how to make a Cool Tik Tok App a new Instagram using Flutter,firebase and visual studio code.
In this tutorial, you will learn how to Upload a Profile Pic to Firestore Data Storage.
🚀 Nice, clean and modern TikTok Clone #App #UI made in #Flutter⚠️
Starter Project : https://github.com/Punithraaj/Flutter_Tik_Tok_Clone_App/tree/Episode1
► Timestamps
0:00 Intro 0:20
Upload Profile Screen
16:35 Image Picker
20:06 Image Cropper
24:25 Firestore Data Storage Configuration.
⚠️ IMPORTANT: If you want to learn, I strongly advise you to watch the video at a slow speed and try to follow the code and understand what is done, without having to copy the code, and then download it from GitHub.
► Social Media
GitHub: https://github.com/Punithraaj/Flutter_Tik_Tok_Clone_App.git
LinkedIn: https://www.linkedin.com/in/roaring-r...
Twitter: https://twitter.com/roaringraaj
Facebook: https://www.facebook.com/flutterdartacademy
► Previous Episode : https://youtu.be/QnL3fr-XpC4
► Playlist: https://youtube.com/playlist?list=PL6vcAuTKAaYe_9KQRsxTsFFSx78g1OluK
I hope you liked it, and don't forget to like,comment, subscribe, share this video with your friends, and star the repository on GitHub!
⭐️ Thanks for watching the video and for more updates don't forget to click on the notification.
⭐️Please comment your suggestion for my improvement.
⭐️Remember to like, subscribe, share this video, and star the repo on Github :)
Hope you enjoyed this video!
If you loved it, you can Buy me a coffee : https://www.buymeacoffee.com/roaringraaj
LIKE & SHARE & ACTIVATE THE BELL Thanks For Watching :-)
https://youtu.be/F_GgZVD4sDk
#flutter tutorial - tiktok clone with firebase #flutter challenge @tiktokclone #fluttertutorial firebase #flutter firebase #flutter pageview #morioh #flutter