Code Monkey home page Code Monkey logo

khayyam-ahmed / favorite_places Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3.03 MB

The purpose of this project was to get familiar with native device features, such as Camera, GPS, and Storage. In the course, you'll learn how to create a mobile app that allows users to save their favorite places by taking pictures, adding titles, and recording the location.

Kotlin 0.19% Swift 3.03% Objective-C 0.05% Dart 32.56% CMake 26.48% C++ 33.07% C 2.00% HTML 2.61%
academind-course flutter maximilian-schwarzmuller

favorite_places's Introduction

Favorite Places App

This Flutter project is a guided project inspired by Maximilian Schwarzmüller's Udemy Course: Learn Flutter & Dart to Build iOS & Android Apps.

Project Features

  • Apply state management using the Riverpod library.
  • Capture and save favorite places with images.
  • Retrieve the user's current location using GPS.
  • Utilize Google Maps API to display maps and location addresses.
  • Save data to the device's local storage.

Project Structure

The project's file structure looks like this:

favorite_places:
    assets:
        .env
    lib:
        models:
            place.dart
        providers:
            places_provider.dart
        screens:
            add_place.dart
            map.dart
            place_details.dart
            places.dart
        widgets:
            image_input.dart
            location_input.dart
            places_list.dart
        main.dart
    pubspec.yaml
    README.md

Screenshots

Home Screen

The Home Screen displays a list of favorite places that the user has saved. Users can tap on a place to view its details.

Add Place Screen

The Add Place Screen allows users to add a new favorite place. Users can enter a place name, take a picture, and select the location either manually on the map or by using the device's GPS.

Place Details Screen

The Place Details Screen displays the details of a saved place, including its name, image, address, and a map showing the location. Users can tap on the map to view it in a larger size.

Map Screen

The Map Screen displays a map with a marker at the user's current location. Users can also tap on the map to select a location.

Packages Used

Flutter Riverpod is a state management library used to manage the app's state in a modular and testable way. It was used to manage the list of favorite places. Below is an example of how it was used:

class FavoritePlacesNotifier extends StateNotifier<List<Place>> {
  FavoritePlacesNotifier() : super([]);

  // ...

  void addFavoritePlace(String name, File img, PlaceLocation location) async {
    // ...

    final db = await getDatabase();
    db.insert('user_places', {
      'id': place.id,
      'title': place.name,
      'image': place.img.path,
      'lat': place.location.latitude,
      'lng': place.location.longitude,
      'address': place.location.address,
    });
    
    state = [...state, place];
  }

  // ...
}

The image_picker package was used to capture images from the device's camera. Here's an example of its usage:

void _takePicture() async {
  final img = await ImagePicker().pickImage(
    source: ImageSource.camera,
    maxWidth: double.infinity,
    maxHeight: double.infinity,
  );

  // ...
}

The location package was used to retrieve the device's current location. Here's an example of its usage:

void getCurrentLocation() async {
  Location location = Location();

  // Check if location services are enabled and request permission if needed

  locationData = await location.getLocation();
  final lat = locationData.latitude;
  final lng = locationData.longitude;

  saveLocation(lat, lng);
}
GoogleMap(
  initialCameraPosition: CameraPosition(
    target: ...
    zoom: 16,
  ),
  onTap: ...,
  markers: {...},
)

Getting Started

Before you start using the project, make sure to replace the placeholder Google Maps API Key in the .env file with your own API key obtained from Google Cloud. (You can get one here.)

GOOGLE_MAPS_API_KEY='your_api_key_here'

Also, see the packages documentation to adjust your Android and iOS projects accordingly.

INSTALLATION

  1. Clone this repository to your local machine:
git clone https://github.com/khayyam-ahmed/favorite_places.git
  1. Create a .env file in the assets folder and add you API key.
  2. Run the app on your device or emulator:
flutter pub get
flutter run

Credits

This project is based on the tutorial by Maximilian Schwarzmüller and was created as a learning exercise in Flutter, Dart, Riverpod state management and Google Cloud Console.

favorite_places's People

Contributors

khayyam-ahmed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.