book_my_seat 1.0.1 book_my_seat: ^1.0.1 copied to clipboard
This is a flutter package to create seat booking layout for bus, theatre, aeroplane etc.
import 'package:book_my_seat/book_my_seat.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
void main() {
runApp(
MaterialApp(
title: "book_my_seat example",
theme: ThemeData(
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: const MyApp(),
),
);
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Set<SeatNumber> selectedSeats = Set();
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 16,
),
const Text("Theatre Screen this side"),
const SizedBox(
height: 16,
),
Flexible(
child: SizedBox(
width: double.maxFinite,
height: 500,
child: SeatLayoutWidget(
onSeatStateChanged: (rowI, colI, seatState) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: seatState == SeatState.selected
? Text("Selected Seat[$rowI][$colI]")
: Text("De-selected Seat[$rowI][$colI]"),
),
);
if (seatState == SeatState.selected) {
selectedSeats.add(SeatNumber(rowI: rowI, colI: colI));
} else {
selectedSeats.remove(SeatNumber(rowI: rowI, colI: colI));
}
},
stateModel: const SeatLayoutStateModel(
pathDisabledSeat: 'assets/svg_disabled_bus_seat.svg',
pathSelectedSeat: 'assets/svg_selected_bus_seats.svg',
pathSoldSeat: 'assets/svg_sold_bus_seat.svg',
pathUnSelectedSeat: 'assets/svg_unselected_bus_seat.svg',
rows: 23,
cols: 33,
seatSvgSize: 10,
currentSeatsState: [
[
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.disabled,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.disabled,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
],
[
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
],
[
SeatState.unselected,
SeatState.unselected,
SeatState.disabled,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.disabled,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
],
[
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
SeatState.empty,
],
[
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.unselected,
SeatState.sold,
SeatState.sold,
],
],
),
),
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
SvgPicture.asset(
'assets/svg_disabled_bus_seat.svg',
width: 15,
height: 15,
),
const Text('Disabled')
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
SvgPicture.asset(
'assets/svg_sold_bus_seat.svg',
width: 15,
height: 15,
),
const Text('Sold')
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
SvgPicture.asset(
'assets/svg_unselected_bus_seat.svg',
width: 15,
height: 15,
),
const Text('Available')
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
SvgPicture.asset(
'assets/svg_selected_bus_seats.svg',
width: 15,
height: 15,
),
const Text('Selected by you')
],
),
],
),
),
const SizedBox(
height: 12,
),
ElevatedButton(
onPressed: () {
setState(() {});
},
child: const Text('Show my selected seat numbers'),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith((states) => const Color(0xFFfc4c4e)),
),
),
const SizedBox(height: 12),
Text(selectedSeats.join(" , "))
],
),
),
);
}
}
class SeatNumber {
final int rowI;
final int colI;
const SeatNumber({required this.rowI, required this.colI});
@override
bool operator ==(Object other) {
return rowI == (other as SeatNumber).rowI && colI == (other as SeatNumber).colI;
}
@override
int get hashCode => rowI.hashCode;
@override
String toString() {
return '[$rowI][$colI]';
}
}