diff --git a/car_booking/assets/icons/adjust.png b/car_booking/assets/icons/adjust.png new file mode 100644 index 0000000..dbbaf56 Binary files /dev/null and b/car_booking/assets/icons/adjust.png differ diff --git a/car_booking/assets/icons/app.png b/car_booking/assets/icons/app.png new file mode 100644 index 0000000..2f27df0 Binary files /dev/null and b/car_booking/assets/icons/app.png differ diff --git a/car_booking/assets/icons/bell.png b/car_booking/assets/icons/bell.png new file mode 100644 index 0000000..da13ce0 Binary files /dev/null and b/car_booking/assets/icons/bell.png differ diff --git a/car_booking/assets/icons/breakdown.png b/car_booking/assets/icons/breakdown.png new file mode 100644 index 0000000..4cf0773 Binary files /dev/null and b/car_booking/assets/icons/breakdown.png differ diff --git a/car_booking/assets/icons/calendar.png b/car_booking/assets/icons/calendar.png new file mode 100644 index 0000000..1e01484 Binary files /dev/null and b/car_booking/assets/icons/calendar.png differ diff --git a/car_booking/assets/icons/climatization.png b/car_booking/assets/icons/climatization.png new file mode 100644 index 0000000..538b264 Binary files /dev/null and b/car_booking/assets/icons/climatization.png differ diff --git a/car_booking/assets/icons/dashboard.png b/car_booking/assets/icons/dashboard.png new file mode 100644 index 0000000..1f55e2c Binary files /dev/null and b/car_booking/assets/icons/dashboard.png differ diff --git a/car_booking/assets/icons/engine.png b/car_booking/assets/icons/engine.png new file mode 100644 index 0000000..10d5255 Binary files /dev/null and b/car_booking/assets/icons/engine.png differ diff --git a/car_booking/assets/icons/information.png b/car_booking/assets/icons/information.png new file mode 100644 index 0000000..c1fe9b3 Binary files /dev/null and b/car_booking/assets/icons/information.png differ diff --git a/car_booking/assets/icons/left-arrow.png b/car_booking/assets/icons/left-arrow.png new file mode 100644 index 0000000..f992dcb Binary files /dev/null and b/car_booking/assets/icons/left-arrow.png differ diff --git a/car_booking/assets/icons/pin.png b/car_booking/assets/icons/pin.png new file mode 100644 index 0000000..05fa15c Binary files /dev/null and b/car_booking/assets/icons/pin.png differ diff --git a/car_booking/assets/icons/right-arrow.png b/car_booking/assets/icons/right-arrow.png new file mode 100644 index 0000000..fc896e0 Binary files /dev/null and b/car_booking/assets/icons/right-arrow.png differ diff --git a/car_booking/assets/icons/search.png b/car_booking/assets/icons/search.png new file mode 100644 index 0000000..bdf340b Binary files /dev/null and b/car_booking/assets/icons/search.png differ diff --git a/car_booking/assets/icons/user.png b/car_booking/assets/icons/user.png new file mode 100644 index 0000000..82fda76 Binary files /dev/null and b/car_booking/assets/icons/user.png differ diff --git a/car_booking/assets/icons/windshield.png b/car_booking/assets/icons/windshield.png new file mode 100644 index 0000000..0af506b Binary files /dev/null and b/car_booking/assets/icons/windshield.png differ diff --git a/car_booking/assets/images/av.png b/car_booking/assets/images/av.png new file mode 100644 index 0000000..0011f6a Binary files /dev/null and b/car_booking/assets/images/av.png differ diff --git a/car_booking/assets/images/bentley.png b/car_booking/assets/images/bentley.png new file mode 100644 index 0000000..9922ed7 Binary files /dev/null and b/car_booking/assets/images/bentley.png differ diff --git a/car_booking/assets/images/cadillac.png b/car_booking/assets/images/cadillac.png new file mode 100644 index 0000000..3243c1e Binary files /dev/null and b/car_booking/assets/images/cadillac.png differ diff --git a/car_booking/assets/images/map.png b/car_booking/assets/images/map.png new file mode 100644 index 0000000..140a7a8 Binary files /dev/null and b/car_booking/assets/images/map.png differ diff --git a/car_booking/assets/images/maserati.png b/car_booking/assets/images/maserati.png new file mode 100644 index 0000000..efddbdd Binary files /dev/null and b/car_booking/assets/images/maserati.png differ diff --git a/car_booking/assets/images/rolls_royce.png b/car_booking/assets/images/rolls_royce.png new file mode 100644 index 0000000..92ae3b1 Binary files /dev/null and b/car_booking/assets/images/rolls_royce.png differ diff --git a/car_booking/lib/constants.dart b/car_booking/lib/constants.dart new file mode 100644 index 0000000..b928f16 --- /dev/null +++ b/car_booking/lib/constants.dart @@ -0,0 +1,22 @@ + +import 'package:flutter/material.dart'; + +import 'model/car.dart'; + + +Color mPrimaryColor = Color(0xFF40ac9c); + +Color mCardColor = Color(0xFF203e5a); +const Color maccentColor = Color.fromRGBO(25, 35, 50, 1); +const Color mbottonColor = Color.fromRGBO(234, 78, 74, 1); +const Color mpinkColor = Color.fromRGBO(136, 30, 255, 1); +const Color mblueColor = Colors.blue; + +const double mpadding = 20.0; + +List carList = [ + Car('assets/images/bentley.png', 120, 'Bentley', '3A 9200', '77/km', '5,5 L'), + Car('assets/images/rolls_royce.png', 185, 'RR', '3A 9200', '77/km', '5,5 L'), + Car('assets/images/maserati.png', 100, 'Maserati', '3A 9200', '77/km', '5,5 L'), + Car('assets/images/cadillac.png', 90, 'Cadillac', '3A 9200', '77/km', '5,5 L'), +]; diff --git a/car_booking/lib/main.dart b/car_booking/lib/main.dart index bcf1b42..ec7c532 100644 --- a/car_booking/lib/main.dart +++ b/car_booking/lib/main.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'screens/available/available_car_screen.dart'; +import 'screens/detail/car_detail_screen.dart'; import 'screens/login/login_screen.dart'; import 'screens/signup/singup_screen.dart'; @@ -28,7 +30,7 @@ class MyApp extends StatelessWidget { routes: { '/': (context) => LoginScreen(), 'CreateNewAccount': (context) => CreateNewAccount(), - + 'AvailableCarScreen': (context) => AvailableCarScreen(), }, ); } diff --git a/car_booking/lib/model/car.dart b/car_booking/lib/model/car.dart new file mode 100644 index 0000000..73972eb --- /dev/null +++ b/car_booking/lib/model/car.dart @@ -0,0 +1,17 @@ +class Car { + String image; + int price; + String brand; + String model; + String co2; + String fuelCons; + + Car( + this.image, + this.price, + this.brand, + this.model, + this.co2, + this.fuelCons, + ); +} diff --git a/car_booking/lib/screens/available/available_car_screen.dart b/car_booking/lib/screens/available/available_car_screen.dart new file mode 100644 index 0000000..00465c8 --- /dev/null +++ b/car_booking/lib/screens/available/available_car_screen.dart @@ -0,0 +1,244 @@ + +import 'package:flutter/material.dart'; +import 'package:flutter/cupertino.dart'; + +import '../../constants.dart'; +import 'widget/build_container.dart'; +import 'widget/car_list_item.dart'; + +class AvailableCarScreen extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.white, + appBar: buildAppBar(), + body: Padding( + padding: + const EdgeInsets.only(left: mpadding, right: mpadding, top: 30), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 10, + ), + _buildText('Book a Car'), + BuildTextSwitch(), + Expanded( + child: ListView.builder( + itemBuilder: (context, index) => Padding( + padding: EdgeInsets.symmetric(horizontal: 15), + child: CarListItem(index), + ), + itemCount: carList.length, + + + ), + + ), + _buildText('Popular Delars'), + _buildDelarContainer(Icons.view_week, 'Dezenix Motors',mpinkColor), + SizedBox(height: 10,), + _buildDelarContainer(Icons.panorama_fish_eye, 'We Ride',mblueColor), + SizedBox(height: 15,), + ], + ), + ), + bottomNavigationBar: BuildBottomNavigationBar(), + ); + } + + AppBar buildAppBar() { + return AppBar( + backgroundColor: Color(0xFF203e5a), + elevation: 0, + leading: IconButton( + icon: Icon( + Icons.nature, + color: Colors.white, + ), + onPressed: () {}, + ), + title: Text('Dzenix Available Cars'), + actions: [ + Row(children: [ + IconButton( + icon: Icon( + Icons.search, + color: Colors.white, + ), + onPressed: () {}, + ), + IconButton( + icon: Icon( + Icons.notifications_active, + color: Colors.white, + ), + onPressed: () {}, + ) + ],) + + ], + ); + } + + Text _buildText(String text) { + return Text( + text, + style: TextStyle( + fontSize: 27, + fontWeight: FontWeight.bold, + color: Colors.black, + letterSpacing: 1.1), + ); + } +} +class BuildTextSwitch extends StatefulWidget { + @override + _BuildTextSwitchState createState() => _BuildTextSwitchState(); +} + + + + + + +class _BuildTextSwitchState extends State { + var driverOn = true; + @override + Widget build(BuildContext context) { + return Row( + children: [ + Text( + 'With a Driver', + style: TextStyle( + fontSize: 15, + color: Colors.black, + letterSpacing: 1.1, + ), + ), + Spacer(), + Switch( + activeColor: Color(0xFF203e5a), + value: driverOn, + onChanged: (value){ + setState(() { + driverOn = value; + }); + }, + ) + ], + ); + } +} +_buildDelarContainer(IconData icon, String text, Color color) { +return Container( + padding: EdgeInsets.all(mpadding/2), + width: double.infinity, + height: 75, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12.0), + color:Color(0xFF203e5a), + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + BuildContainer( + child: Icon(icon,color: Colors.white,), + color: color, + ), + SizedBox(width: 10.0,), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + style: TextStyle( + fontSize: 17, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + Text( + '823 Wall Street Apt. 425', + style: TextStyle( + fontSize: 13, + color: Colors.white, + letterSpacing: 1.1 + ), + ), + ], + ), + Spacer(), + Column( + crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( + children: [ + Icon(Icons.star,size: 15,color: Colors.yellow,), + Icon(Icons.star,size: 15,color: Colors.yellow,), + Icon(Icons.star,size: 15,color: Colors.yellow,), + Icon(Icons.star,size: 15,color: Colors.yellow,), + Icon(Icons.star_border,size: 15,color: Colors.yellow,) + ], + ), + Text( + '23 Offers', + style: TextStyle( + fontSize: 13, + color: Colors.white, + letterSpacing: 1.1 + ), + ), + ], + ) + ], + ), +); +} + +class BuildBottomNavigationBar extends StatefulWidget { + @override + _BuildBottomNavigationBarState createState() => _BuildBottomNavigationBarState(); +} + +class _BuildBottomNavigationBarState extends State { + List bottomNavIcons = [ + 'assets/icons/app.png', + 'assets/icons/calendar.png', + 'assets/icons/pin.png', + 'assets/icons/user.png', + ]; + int selected = 0 ; + @override + Widget build(BuildContext context) { + return Container( + padding: EdgeInsets.symmetric(horizontal: 25, vertical: 15), + color:Color(0xFF203e5a), + height: 65, + child: ListView.builder( + scrollDirection: Axis.horizontal, + itemCount: bottomNavIcons.length, + itemBuilder: (context, index) => GestureDetector( + onTap: (){ + setState(() { + selected = index; + }); + }, + child: Padding( + padding: EdgeInsets.only(right: mpadding * 2, left: mpadding), + child: Image.asset( + bottomNavIcons[index], + height: 40, + color: selected == index ? mbottonColor :Colors.grey, + ), + ), + ) + ), + ); + } +} + + + + diff --git a/car_booking/lib/screens/available/widget/build_container.dart b/car_booking/lib/screens/available/widget/build_container.dart new file mode 100644 index 0000000..b7857c4 --- /dev/null +++ b/car_booking/lib/screens/available/widget/build_container.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +import '../../../constants.dart'; + +/** + * @author Punithraj + */ + +class BuildContainer extends StatelessWidget { + final Color color; + final Widget child; + + const BuildContainer({ required this.color, required this.child}) ; + + @override + Widget build(BuildContext context) { + return Container( + width: 45, + height: 45, + padding: EdgeInsets.all(10.0), + decoration: BoxDecoration( + color: color, + border: Border.all(color: maccentColor, width: 1.0), + borderRadius: BorderRadius.circular(10), + ), + child: child, + ); + } +} \ No newline at end of file diff --git a/car_booking/lib/screens/available/widget/car_infomation.dart b/car_booking/lib/screens/available/widget/car_infomation.dart new file mode 100644 index 0000000..5185b7b --- /dev/null +++ b/car_booking/lib/screens/available/widget/car_infomation.dart @@ -0,0 +1,72 @@ + +import 'package:flutter/material.dart'; + +import '../../../constants.dart'; +import '../../../model/car.dart'; +import '../../../widget/attribute.dart'; + +class CarInfomation extends StatelessWidget { + const CarInfomation({ + + required this.car, + }) ; + + final Car car; + + @override + Widget build(BuildContext context) { + return Container( + width: double.infinity, + margin: EdgeInsets.only(left: 24, right: 24,top: 50), + padding: EdgeInsets.all(16), + decoration: BoxDecoration( + color: mCardColor, + borderRadius: BorderRadius.circular(16), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '\$${car.price}', + style: TextStyle( + color: Colors.white, + fontSize: 24, + fontWeight: FontWeight.bold, + ), + ), + Text( + 'price/hr', + style: TextStyle( + color: Colors.white, + ), + ), + SizedBox( + height: 16, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Attribute( + value: car.brand, + name: 'Brand', + ), + Attribute( + value: car.model, + name: 'Model No', + ), + Attribute( + value: car.co2, + name: 'CO2', + ), + Attribute( + value: car.fuelCons, + name: 'Fule Cons.', + ), + ], + ) + ], + ), + ); + } +} + diff --git a/car_booking/lib/screens/available/widget/car_list_item.dart b/car_booking/lib/screens/available/widget/car_list_item.dart new file mode 100644 index 0000000..0fb1338 --- /dev/null +++ b/car_booking/lib/screens/available/widget/car_list_item.dart @@ -0,0 +1,48 @@ + +import 'package:flutter/material.dart'; + +import '../../../constants.dart'; +import '../../../model/car.dart'; +import '../../detail/car_detail_screen.dart'; +import 'car_infomation.dart'; + +class CarListItem extends StatelessWidget { + const CarListItem( + this.index, + + ) ; + + final int index; + + @override + Widget build(BuildContext context) { + Car car = carList[index]; + return GestureDetector( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return CarDetailScreen(car); + }, + ), + ); + }, + child: Container( + margin: EdgeInsets.only(bottom: 20), + child: Stack( + children: [ + CarInfomation(car: car), + Positioned( + right: 40, + child: Image.asset( + car.image, + height: 100, + ), + ) + ], + ), + ), + ); + } +} diff --git a/car_booking/lib/screens/detail/car_detail_screen.dart b/car_booking/lib/screens/detail/car_detail_screen.dart new file mode 100644 index 0000000..1f13d64 --- /dev/null +++ b/car_booking/lib/screens/detail/car_detail_screen.dart @@ -0,0 +1,48 @@ + +import 'package:flutter/material.dart'; + +import '../../model/car.dart'; +import 'widget/car_detail_infomation.dart'; +import 'widget/my_appbar.dart'; + +class CarDetailScreen extends StatelessWidget { + final Car car; + + CarDetailScreen(this.car); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Container( + child: Stack( + children: [ + Image.asset( + 'assets/images/map.png', + width: double.infinity, + fit: BoxFit.fill, + ), + MyAppbar(), + Positioned( + left: 24, + right: 24, + bottom: 24, + child: Stack( + children: [ + CarDetailInfomation(car: car), + Positioned( + right: 16, + child: Image.asset( + car.image, + height: 100, + ), + ) + ], + ), + ), + ], + ), + ), + ); + } +} + diff --git a/car_booking/lib/screens/detail/widget/car_detail_infomation.dart b/car_booking/lib/screens/detail/widget/car_detail_infomation.dart new file mode 100644 index 0000000..ae436ee --- /dev/null +++ b/car_booking/lib/screens/detail/widget/car_detail_infomation.dart @@ -0,0 +1,232 @@ + +import 'package:flutter/material.dart'; + +import '../../../constants.dart'; +import '../../../model/car.dart'; +import '../../../widget/attribute.dart'; +import '../../../widget/rating_bar.dart'; + +class CarDetailInfomation extends StatelessWidget { + const CarDetailInfomation({ + + required this.car, + }) ; + + final Car car; + + @override + Widget build(BuildContext context) { + return Container( + padding: EdgeInsets.all(16), + margin: EdgeInsets.only(top: 50), + decoration: BoxDecoration( + color:Colors.white, borderRadius: BorderRadius.circular(16)), + child: Column( + children: [ + CarInfo(car: car), + Divider( + height: 16, + color: Colors.black54, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + 'assets/images/av.png', + height: 120, + ), + SizedBox( + width: 16, + ), + Expanded( + child: Column( + children: [ + DriverInfo(), + SizedBox( + height: 12, + ), + DiverAppraise(), + SizedBox( + height: 12, + ), + DriverCall(), + ], + ), + ) + ], + ) + ], + ), + ); + } +} + +class DriverCall extends StatelessWidget { + + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FlatButton( + onPressed: () {}, + color: mCardColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(36), + ), + child: Text( + 'Call', + style: TextStyle( + color: Colors.white, + ), + ), + ), + FlatButton( + onPressed: () {}, + color: mCardColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(36), + ), + child: Text( + 'Book Now', + style: TextStyle( + color: Colors.white, + ), + ), + ) + ], + ); + } +} + +class DiverAppraise extends StatelessWidget { + + @override + Widget build(BuildContext context) { + return Row( + children: [ + Text( + '5.0', + style: TextStyle(), + ), + SizedBox( + width: 6, + ), + RatingBar( + onRatingUpdate: (value) {}, + size: 14, + selectColor: Colors.yellow, padding: 0.0, + ), + ], + ); + } +} + +class DriverInfo extends StatelessWidget { + + @override + Widget build(BuildContext context) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Jesica Smith', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w500, + ), + ), + Text( + 'License NWR 369852', + style: TextStyle( + fontSize: 10, + ), + ), + ], + ), + Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + '369', + style: TextStyle( + fontSize: 16, + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ), + Text( + 'Ride', + style: TextStyle( + fontSize: 10, + ), + ), + ], + ) + ], + ); + } +} + +class CarInfo extends StatelessWidget { + const CarInfo({ + + required this.car, + }) ; + + final Car car; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '\$${car.price}', + style: TextStyle( + color: Colors.yellow, + fontSize: 24, + fontWeight: FontWeight.bold, + ), + ), + Text( + 'price/hr', + style: TextStyle( + color: Colors.yellow, + ), + ), + SizedBox( + height: 16, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Attribute( + value: car.brand, + name: 'Brand', + textColor: Colors.black87, + ), + Attribute( + value: car.model, + name: 'Model No', + textColor: Colors.black87, + ), + Attribute( + value: car.co2, + name: 'CO2', + textColor: Colors.black87, + ), + Attribute( + value: car.fuelCons, + name: 'Fule Cons.', + textColor: Colors.black87, + ), + ], + ) + ], + ); + } +} diff --git a/car_booking/lib/screens/detail/widget/my_appbar.dart b/car_booking/lib/screens/detail/widget/my_appbar.dart new file mode 100644 index 0000000..ce2e431 --- /dev/null +++ b/car_booking/lib/screens/detail/widget/my_appbar.dart @@ -0,0 +1,39 @@ +import 'package:flutter/material.dart'; + +class MyAppbar extends StatelessWidget { + + @override + Widget build(BuildContext context) { + return SafeArea( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + IconButton( + icon: Icon( + Icons.arrow_back_ios, + color: Colors.white, + ), + onPressed: () { + Navigator.pop(context); + }, + ), + Text( + 'Car Detail', + style: TextStyle( + color: Colors.white, + fontSize: 18, + fontWeight: FontWeight.w500, + ), + ), + IconButton( + icon: Icon( + Icons.menu, + color: Colors.white, + ), + onPressed: () {}, + ), + ], + ), + ); + } +} diff --git a/car_booking/lib/widget/attribute.dart b/car_booking/lib/widget/attribute.dart new file mode 100644 index 0000000..643572a --- /dev/null +++ b/car_booking/lib/widget/attribute.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; + +class Attribute extends StatelessWidget { + const Attribute({ + + required this.name, + required this.value, + this.textColor = Colors.white, + }); + + final String name, value; + final Color textColor; + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + value, + style: TextStyle( + color: textColor, + fontSize: 16, + fontWeight: FontWeight.w500, + ), + ), + Text( + name, + style: TextStyle( + color: textColor, + fontSize: 12, + ), + ) + ], + ); + } +} diff --git a/car_booking/lib/widget/rating_bar.dart b/car_booking/lib/widget/rating_bar.dart new file mode 100644 index 0000000..7b56afd --- /dev/null +++ b/car_booking/lib/widget/rating_bar.dart @@ -0,0 +1,174 @@ +import 'package:flutter/material.dart'; + +class RatingBar extends StatefulWidget { + final int count; + final double maxRating; + final double value; + final double size; + final double padding; + final bool selectAble; + final Color selectColor; + final ValueChanged onRatingUpdate; + + RatingBar( + {this.maxRating = 10.0, + this.count = 5, + this.value = 10.0, + this.size = 20, + required this.padding, + this.selectColor = Colors.blue, + this.selectAble = false, + required this.onRatingUpdate}); + + @override + _RatingBarState createState() => _RatingBarState(); +} + +class _RatingBarState extends State { + late double value; + + @override + Widget build(BuildContext context) { + value = widget.value; + return Listener( + child: buildRowRating(), + onPointerDown: (PointerDownEvent event) { + double x = event.localPosition.dx; + if (x < 0) x = 0; + pointValue(x); + }, + onPointerMove: (PointerMoveEvent event) { + double x = event.localPosition.dx; + if (x < 0) x = 0; + pointValue(x); + }, + onPointerUp: (_) {}, + behavior: HitTestBehavior.deferToChild, + ); + } + + pointValue(double dx) { + if (!widget.selectAble) { + return; + } + if (dx >= + widget.size * widget.count + widget.padding * (widget.count - 1)) { + value = widget.maxRating; + } else { + for (double i = 1; i < widget.count + 1; i++) { + if (dx > widget.size * i + widget.padding * (i - 1) && + dx < widget.size * i + widget.padding * i) { + value = i * (widget.maxRating / widget.count); + break; + } else if (dx > widget.size * (i - 1) + widget.padding * (i - 1) && + dx < widget.size * i + widget.padding * i) { + value = (dx - widget.padding * (i - 1)) / + (widget.size * widget.count) * + widget.maxRating; + break; + } + } + } + setState(() { + widget.onRatingUpdate(value.toStringAsFixed(1)); + }); + } + + Widget buildRowRating() { + return Container( + child: Stack( + children: [ + Row( + mainAxisSize: MainAxisSize.min, + children: buildNormalRow(), + ), + Row( + mainAxisSize: MainAxisSize.min, + children: buildRow(), + ) + ], + ), + ); + } + + List buildRow() { + int full = fullStars(); + List children = []; + for (int i = 0; i < full; i++) { + children.add(Icon( + Icons.star, + color: widget.selectColor, + size: widget.size, + )); + if (i < widget.count - 1) { + children.add( + SizedBox( + width: widget.padding, + ), + ); + } + } + if (full < widget.count) { + children.add(ClipRect( + clipper: SMClipper(rating: star() * widget.size), + child: Icon( + Icons.star, + color: widget.selectColor, + size: widget.size, + ), + )); + } + return children; + } + + List buildNormalRow() { + List children = []; + for (int i = 0; i < widget.count; i++) { + children.add(Icon( + Icons.star, + color: Colors.grey, + size: widget.size, + )); + if (i < widget.count - 1) { + children.add(SizedBox( + width: widget.padding, + )); + } + } + return children; + } + + int fullStars() { + if (value != null) { + return (value / (widget.maxRating / widget.count)).floor(); + } + return 0; + } + + double star() { + if (value != null) { + if (widget.count / fullStars() == widget.maxRating / value) { + return 0; + } + return (value % (widget.maxRating / widget.count)) / + (widget.maxRating / widget.count); + } + return 0; + } +} + +class SMClipper extends CustomClipper { + final double rating; + + SMClipper({required this.rating}) : assert(rating != null); + + @override + Rect getClip(Size size) { + return Rect.fromLTRB(0.0, 0.0, rating, size.height); + } + + @override + bool shouldReclip(SMClipper oldClipper) { + return rating != oldClipper.rating; + } +} diff --git a/car_booking/pubspec.yaml b/car_booking/pubspec.yaml index 1089905..5c1cef4 100644 --- a/car_booking/pubspec.yaml +++ b/car_booking/pubspec.yaml @@ -64,6 +64,8 @@ flutter: # To add assets to your application, add an assets section, like this: assets: - assets/images/ + - assets/icons/ + - assets/fonts/ # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see