Skip to content

mohammadkamal/wazeefa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wazeefa

A career finder application

Tools

Gallery

Documentation

Fetch data from API

To fetch data from RESTful API, You need to use http package Examine the following example:

Future<List<Job>> fetchJobs() async {
  final respone = await http
      .get(Uri.parse('https://jobs.github.com/positions.json?description='));
  final parsed = jsonDecode(respone.body).cast<Map<String, dynamic>>();
  return parsed.map<Job>((json) => Job.fromJson(json)).toList();
}

Search for specific data

Examine the following example:

Future<List<Job>> searchJobs(
    String description, String location, bool fullTime) async {
  String descriptionVariable =
      description.isNotEmpty ? 'description=' + description : 'description=';
  String locationVariable =
      location.isNotEmpty ? '&location=' + location : '&location=';
  String fullTimeVariable = fullTime ? '&full_time=true' : '';

  final response = await http.get(Uri.parse(
      'https://jobs.github.com/positions.json?' +
          descriptionVariable +
          fullTimeVariable +
          locationVariable));
  final parsed = jsonDecode(response.body).cast<Map<String, dynamic>>();
  return parsed.map<Job>((json) => Job.fromJson(json)).toList();
}

For more information, see Fetch data from the internet at Flutter documentation.

For the whole code, you can see Fetch API functions code

Store data on local device

To store data on local device, You can use SQLite database to save your data on your phone. To download the package, go to sqflite

static Future<Database> futureDatabase;
static Database database;

  void onDatabaseIntialize() async {
    var databasePath = await getDatabasesPath();
    String path = join(databasePath, 'saved_jobs_database.db');

    futureDatabase = openDatabase(path, onCreate: (db, version) {
      return db.execute(
          'CREATE TABLE savedJobs(jobID TEXT PRIMARY KEY, type TEXT, jobURL TEXT, createTime TEXT, companyName TEXT, companyURL TEXT, location TEXT, title TEXT, description TEXT, companyLogoURL TEXT, howToApply TEXT)');
    }, version: 1);

    database = await futureDatabase;
  }

To add data (in our case jobs):

Future<void> addJob(Job job) async {
    await database.insert('savedJobs', job.toDatabaseMap(),
    conflictAlgorithm: ConflictAlgorithm.replace);
}

To remove data:

Future<void> deleteJob(String id) async {
    await database.delete('savedJobs', where: 'jobID = ?', whereArgs: [id]);
}

To see the whole code, visit Jobs Database