Git Product home page Git Product logo

ballsquad_project's Introduction

BallSquad Technical Test Solution

A simple application for searching authors and authors' infos.

Used Technologies and Packages

UI: Flutter
State Manangement: Bloc/Cubit
API Calls: Dio

Kullanım/Örnekler

return MultiBlocProvider(
      providers: [
        BlocProvider<AuthorsCubit>(
          create: (context) => AuthorsCubit(SampleAuthorsRepo()),
        ),
      ],
}

Bloc entegrated to project.

abstract class AuthorsState extends Equatable {
  const AuthorsState();
  @override
  List<Object> get props => [];
}

class AuthorsInitial extends AuthorsState {
  const AuthorsInitial();
}

class AuthorsLoading extends AuthorsState {
  const AuthorsLoading();
}

class AuthorsLoaded extends AuthorsState {
  final Authors response;
  const AuthorsLoaded(this.response);
  @override
  List<Object> get props => [response];
}

A simple status check was written to check the status of the Bloc. An abstract class was used to make it easier to write tests. Equtable integrated to control equations.

class SampleAuthorsRepo implements AuthorsRepo {
  final baseUrl = AppConstants.baseUrl;
  late final Dio _dio;
  SampleAuthorsRepo() {
    _dio = Dio(
      BaseOptions(
        baseUrl: baseUrl,
      ),
    );
  }

  @override
  Future<Authors> getAuthors(String value) async {
    try {
      final response = await _dio.get(value);
      if (response.statusCode == HttpStatus.ok) {
        final data = response.data;
        final Authors authors = Authors.fromJson(data);
        return authors;
      } else {
        throw NetworkError(AppConstants.errorMessage);
      }
    } catch (error) {
      throw NetworkError('Error: $error');
    }
  }
}

class NetworkError implements Exception {
  final String message;
  NetworkError(this.message);
}

Dio package used for API request. Also made a custom error for handle the errors. Here is example of making a request for API with Dio package.

                  return ListView.builder(
                    itemCount: state.response.docs?.length ?? 0,
                    itemBuilder: (context, index) {
                      final author = state.response.docs?[index];
                      return Card(
                        child: ListTile(
                          onTap: () {
                            if (author == null) return;
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                builder: (context) => AuthorDetailsPage(authorDetails: author),
                              ),
                            );
                          },
                          title: Text(author?.name ?? ""),
                          subtitle: Text(author?.birthDate ?? ""),
                        ),
                      );
                    },
                  );

This piece of code was written to show the writers that appeared on the screen as a result of the search.

class AppConstants {
  static String baseUrl = 'https://openlibrary.org/search/authors.json?q=';
  static String errorMessage = 'Failed to fetch authors';
  static String initialPageMessage = 'Welcome To Authors Page!\nSearch for authors to get started!';
}

This piece of code is written for app constants.

export 'package:flutter/material.dart';
export 'package:ballsquad_project/feature/authors/bloc/authors_cubit.dart';
export 'package:ballsquad_project/feature/authors/views/author_view.dart';
export 'package:ballsquad_project/feature/authors/repo/authors_repo.dart';
export 'package:ballsquad_project/feature/authors/bloc/authors_state.dart';
export 'package:ballsquad_project/feature/authors/model/authors.dart';
export 'package:ballsquad_project/feature/authors/views/author_detail_view.dart';
export 'package:flutter_bloc/flutter_bloc.dart';

Export file was written to reduce import complexity.

Screenshots

HomePage Screenshot_20240216_231600 Searching Part Screenshot_20240216_231616 Author Detail Page Screenshot_20240216_231631

resim_2024-02-17_002737477

Demo

Click on the link to watch the screen video.

Screen_Recording_20240216_230504.mp4

Support

Send an e-mail to [email protected] for support.

ballsquad_project's People

Contributors

hikmetmelik avatar

Stargazers

Hikmet Melik avatar  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.