Code Monkey home page Code Monkey logo

book_my_seat's Introduction

book_my_seat

This is a flutter package to create seat booking layout for bus, theatre, aeroplane etc. This gives you facility to select a seat by gestures like zoom-in, zoom-out, pan etc.

Some examples(below is for theatre but you can implement the package for bus etc also)

" " gif

Example project and blog for better understanding ๐Ÿš€

Read my article with example

Getting Started ๐Ÿคฉ

Add this dependency in your pubspec.yaml file

dependencies:
  book_my_seat: <version number>

How to use โŒจ๏ธ

First, import it:

import 'package:book_my_seat/book_my_seat.dart';

Simply create SeatLayoutWidget widget and add the required parameters.

Example:

SeatLayoutWidget(
  onSeatStateChanged: (rowIndex, colIndex, updatedSeatState) {
    print("tapped $rowIndex $colIndex $updatedSeatState");
  },
  stateModel: SeatLayoutStateModel(
    rows: 12,
    cols: 15,
    seatSvgSize: 30,
    pathUnSelectedSeat: 'assets/svg_unselected_bus_seat.svg',
    pathSelectedSeat: 'assets/svg_selected_bus_seat.svg',
    pathSoldSeat: 'assets/svg_sold_bus_seat.svg',
    pathDisabledSeat: 'assets/svg_disabled_bus_seat.svg',
    currentSeatsState: <explained below>,
  ),
)

Parameters explained:

  • onSeatStateChanged: - This is a callback method which gets called when user clicks on a seat which has current state equals to either SeatState.selected or SeatState.unselected. The params in this method are:
    rowIndex - the index of the row where this seat is situated
    colIndex - the index of the column where this seat is situated
    updatedSeatState - this is the updated state of the seat after user clicks on the seat. It is an enum of type SeatState

  • stateModel: - It is an object of class SeatLayoutStateModel which describes the initial state of the whole layout(maybe bus or aeroplane or theatre). The params in this method are:
    rows - number of rows in the area(I will refer bus/aeroplane/theatre etc as area from now onwards)
    cols - number of columns in the area.
    seatSvgSize - size of individual seat
    pathUnSelectedSeat, pathSelectedSeat, pathSoldSeat, pathDisabledSeat - path of the svg assets you want to show for unselected(available), selected(by you right now), already sold and disabled(non-choosable) seats respectively
    currentSeatsState - this is the main parameter. It is a 2D list i.e. of type List<List<SeatState>> (SeatState enum is explained below). This describes the initial state of the area i.e. state of each seat whether it is already sold or unselected(available) or selected by you or disabled(non-selectable).

SeatState enum:

It is a dart enum. This describes the current state of individual seat. This currently holds 5 states unselected, selected, sold, disabled and empty.
Brief description of each:

  • unselected - state when a seat is available and user can select it
  • selected - state when user has selected an unselected(available) seat (i.e. a seat which had its state == unselected)
  • sold - state when it is already sold to some other user
  • disabled - state when a seat is disabled and nobody can select it
  • empty - state of the cell in 2D area which is an empty place(consider vacant ground) in the bus/theatre/aeroplane etc. This can mimic staircase or aisle or some other place in the area where there are no seats

NOTE: User can only click on seats which have state equals to SeatState.selected or SeatState.unselected.

Example project and blog for better understanding ๐Ÿš€

Read my article with example

Contributors ๐Ÿ’ป

Prateek Sharma - Linkedin | Github

If you like this package, please do a thumbs up on it on pub.dev, give star on github and you can buy me a coffee also ๐Ÿ™๐Ÿ‘‡

Buy Me A Coffee

book_my_seat's People

Contributors

sharmaprateek196 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

book_my_seat's Issues

Support for latest flutter SVG

Try to pug get, but got this error, i am using flutter_svg: ^2.0.5.

Resolving dependencies...
Because every version of book_my_seat depends on flutter_svg ^1.0.2 and project depends on flutter_svg ^2.0.5, book_my_seat is forbidden.
So, because project depends on book_my_seat ^1.0.1, version solving failed.
exit code 1

Feature Request

Hello,

First of all, thank you for the sample project. I will use it in my own project. I think it would be good to add additional features to be more useful to people who will use it in the future.

Useful features;

  1. It can be effective that it supports image formats like "Png","Jpg" besides Svg format.
  2. Adding space between rows and columns can improve the quality of the view.
  3. The area can be adjusted to be scrollable left and right.

how to hide some selected seats

I want to hide some selected seats like I have only a few seats space I dont want to show some starts and end seats in a selected row then How can i do it

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.