diff --git a/example/lib/main.dart b/example/lib/main.dart index 261819ea..ad7688d7 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -41,7 +41,7 @@ class _MyHomePageState extends State TabController tabController; final _ratingController = TextEditingController(); - double _rating = 3.5; + double _rating = 3; double _userRating = 4.5; @override @@ -138,7 +138,24 @@ class _MyHomePageState extends State backgroundColor: Colors.teal, // centerTitle: true, // leading: GFIconButton(icon: Icon(Icons.directions_bus), onPressed: (){}), - title: const Text('UI Kit'), + title: +// const Text('UI Kit'), + GFSegmentTabs( + tabController: tabController, + initialIndex: 0, + length: 3, + tabs: const [ + Text( + 'Tab1', + ), + Text( + 'Tab2', + ), + Text( + 'Tab3', + ), + ], + ), // bottom: TabBar( // controller: tabController, // tabs: [ @@ -147,7 +164,7 @@ class _MyHomePageState extends State // Tab(icon: Icon(Icons.directions_bike)), // ], // ), - searchBar: true, +// searchBar: true, // searchHintText: "aaaaaaa", // searchHintStyle: TextStyle(fontSize: 18.0, color: Colors.redAccent), // searchStyle: TextStyle(fontSize: 10.0, color: Colors.green), @@ -175,20 +192,12 @@ class _MyHomePageState extends State // Container(color: Colors.green), // Container(color: Colors.blue) // ]), - -<<<<<<< HEAD - SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, -======= -// SingleChildScrollView( -// child: - Column( - mainAxisAlignment: MainAxisAlignment.start, ->>>>>>> ccc97fde38d7e90bca8ef572ba85c4254a92c687 - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - GFSearchBar( + SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + GFSearchBar( // searchBoxInputDecoration: InputDecoration( // enabledBorder: OutlineInputBorder( // borderSide: BorderSide( @@ -197,103 +206,96 @@ class _MyHomePageState extends State // borderRadius: BorderRadius.circular(50) // ), // ), - searchList: list, + searchList: list, // hideSearchBoxWhenItemSelected: false, // overlaySearchListHeight: 100.0, - searchQueryBuilder: (query, list) => list - .where((item) => - item.toLowerCase().contains(query.toLowerCase())) - .toList(), - overlaySearchListItemBuilder: (item) => Container( - padding: const EdgeInsets.all(8), - child: Text( - item, - style: const TextStyle(fontSize: 18), + searchQueryBuilder: (query, list) => list + .where((item) => + item.toLowerCase().contains(query.toLowerCase())) + .toList(), + overlaySearchListItemBuilder: (item) => Container( + padding: const EdgeInsets.all(8), + child: Text( + item, + style: const TextStyle(fontSize: 18), + ), ), - ), // noItemsFoundWidget: Container( // color: Colors.green, // child: Text("no items found..."), // ), - onItemSelected: (item) { - setState(() { - print('ssssssss $item'); - }); - }), + onItemSelected: (item) { + setState(() { + print('ssssssss $item'); + }); + }), - GFRating( - rating: _rating, - itemSize: 50, -// filledIcon: Image.asset( -// 'lib/assets/heart.png', -// height: 50, -// width: 50, -// color: Colors.amber, -// ), -// halfFilledIcon: Image.asset( -// 'lib/assets/heart_half.png', -// height: 50, -// width: 50, -// color: Colors.amber, -// ), -// defaultIcon: Image.asset( -// 'lib/assets/heart_border.png', -// height: 50, -// width: 50, -// color: Colors.amber, -// ), + GFRating( + value: _rating, +// size: 50, + filledIcon: Icon( + Icons.done_outline, + size: 40, + color: Colors.teal, + ), + halfFilledIcon: Icon( + Icons.done_all, + size: 40, + color: Colors.teal.withOpacity(0.75), + ), + defaultIcon: Icon( + Icons.done, + size: 40, + color: Colors.teal.withOpacity(0.25), + ), + spacing: 8, +// color: Colors.teal, +// borderColor: Colors.tealAccent, // allowHalfRating: false, - spacing: 8, - color: Colors.teal, - borderColor: Colors.tealAccent, - onRatingChanged: (value) { - setState(() { - _rating = value; - print('user selected $_rating'); - }); - }, - ), - - SizedBox( - height: 20, - child: Text('selected rating ${_rating.toStringAsFixed(1)}'), - ), - - GFRating( - rating: _userRating, - itemSize: 50, - filledIcon: Image.asset( - 'lib/assets/heart.png', - height: 50, - width: 50, - color: Colors.amber, - ), - halfFilledIcon: Image.asset( - 'lib/assets/heart_half.png', - height: 50, - width: 50, - color: Colors.amber, - ), - defaultIcon: Image.asset( - 'lib/assets/heart_border.png', - height: 50, - width: 50, - color: Colors.amber, - ), - ratingController: _ratingController, - textFormRating: true, - spacing: 8, - color: Colors.teal, - borderColor: Colors.tealAccent, - suffixIcon: MaterialButton( - onPressed: () { + onChanged: (value) { setState(() { - _userRating = double.parse(_ratingController.text ?? '0.0'); + _rating = value; + print('user selected $_rating'); }); }, - child: const Text('Rate'), ), - ), + + GFRating( + value: _userRating, + filledIcon: Image.asset( + 'lib/assets/heart.png', + height: 50, + width: 50, + color: Colors.amber, + ), + halfFilledIcon: Image.asset( + 'lib/assets/heart_half.png', + height: 50, + width: 50, + color: Colors.amber, + ), + defaultIcon: Image.asset( + 'lib/assets/heart_border.png', + height: 50, + width: 50, + color: Colors.amber, + ), + spacing: 8, + color: Colors.teal, + borderColor: Colors.tealAccent, + controller: _ratingController, + textForm: true, + suffixIcon: GFButton( + type: GFButtonType.transparent, + onPressed: () { + setState(() { + _userRating = + double.parse(_ratingController.text ?? '0.0'); + }); + }, + child: const Text('Rate'), + ), + ), // GFCard( // content: Column( @@ -660,12 +662,12 @@ class _MyHomePageState extends State // ], // )), - // Image.asset( - // 'lib/assets/food.jpeg', - // fit: BoxFit.cover, - // color: Color(0xff0d69ff).withOpacity(1.0), - // colorBlendMode: BlendMode.softLight, - // ), + // Image.asset( + // 'lib/assets/food.jpeg', + // fit: BoxFit.cover, + // color: Color(0xff0d69ff).withOpacity(1.0), + // colorBlendMode: BlendMode.softLight, + // ), // GFCard( // content: Container( @@ -1131,7 +1133,7 @@ class _MyHomePageState extends State //// border: Border.all(color: Colors.pink, width: 2.0), // ), // GFAvatar( - // radius: 20.0, + // radius: 20.0, // maxRadius: 50, // child: Text("de"), @@ -1231,8 +1233,8 @@ class _MyHomePageState extends State //// borderSide: BorderSide(color: Colors.pink, width: 1.0, style: BorderStyle.solid), //// borderShape: RoundedRectangleBorder(side: BorderSide(color: Colors.pink, width: 2.0, style: BorderStyle.solid), borderRadius: BorderRadius.zero), // ), - ], - ), + ], + ), // ), // bottomNavigationBar: GFTabBar( // initialIndex: 0, @@ -1280,6 +1282,6 @@ class _MyHomePageState extends State // color: Colors.black, // fontFamily: 'OpenSansBold', // ), -// ), + ), ); } diff --git a/lib/components/rating/gf_rating.dart b/lib/components/rating/gf_rating.dart index 9f314f05..15c2fd1b 100644 --- a/lib/components/rating/gf_rating.dart +++ b/lib/components/rating/gf_rating.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:getflutter/getflutter.dart'; typedef RatingChangeCallback = void Function(double rating); @@ -6,22 +7,22 @@ class GFRating extends StatefulWidget { const GFRating({ this.itemCount = 5, this.spacing = 0.0, - this.rating = 0.0, + this.value = 0.0, this.defaultIcon, - this.onRatingChanged, + this.onChanged, this.color, this.borderColor, - this.itemSize = 25, + this.size = GFSize.medium, this.filledIcon, this.halfFilledIcon, this.allowHalfRating = true, - this.textFormRating = false, + this.textForm = false, this.suffixIcon, - this.ratingController, + this.controller, this.inputDecorations, this.margin = const EdgeInsets.symmetric(vertical: 16), this.padding = const EdgeInsets.symmetric(horizontal: 16), - }) : assert(rating != null); + }) : assert(value != null); /// defines total number of rating items final int itemCount; @@ -32,8 +33,8 @@ class GFRating extends StatefulWidget { /// defines the border color of [halfFilledIcon] final Color borderColor; - /// defines the size of items - final double itemSize; + /// defines the size of items. GFSize can be used for size variations like small. medium. large + final dynamic size; /// if true, allow half rating of items. Default it will be in true state final bool allowHalfRating; @@ -51,19 +52,19 @@ class GFRating extends StatefulWidget { final double spacing; /// defines the rating value - final double rating; + final double value; /// return current rating whenever rating is updated - final RatingChangeCallback onRatingChanged; + final RatingChangeCallback onChanged; /// if true, shows rating [TextFormField] with the rating bar, that allows the user input to show rating - final bool textFormRating; + final bool textForm; /// defines the design and funtion of rating [TextFormField]'s suffix icon final Widget suffixIcon; /// controls the [TextField] Controller of rating [TextFormField] - final TextEditingController ratingController; + final TextEditingController controller; /// defines the [InputDecoration] of rating [TextFormField] final InputDecoration inputDecorations; @@ -81,24 +82,24 @@ class GFRating extends StatefulWidget { class _GFRatingState extends State { Widget buildRatingBar(BuildContext context, int index) { Widget icon; - if (index >= widget.rating) { + if (index >= widget.value) { icon = widget.defaultIcon != null ? widget.defaultIcon : Icon( Icons.star_border, color: widget.borderColor ?? Theme.of(context).primaryColor, - size: widget.itemSize, + size: GFSizesClass.getGFSize(widget.size), ); - } else if (!widget.textFormRating - ? index > widget.rating - (widget.allowHalfRating ? 0.5 : 1.0) && - index < widget.rating - : index + 1 == widget.rating + 0.5) { + } else if (!widget.textForm + ? index > widget.value - (widget.allowHalfRating ? 0.5 : 1.0) && + index < widget.value + : index + 1 == widget.value + 0.5) { icon = widget.halfFilledIcon != null ? widget.halfFilledIcon : Icon( Icons.star_half, color: widget.color ?? Theme.of(context).primaryColor, - size: widget.itemSize, + size: GFSizesClass.getGFSize(widget.size), ); } else { icon = widget.filledIcon != null @@ -106,20 +107,20 @@ class _GFRatingState extends State { : Icon( Icons.star, color: widget.color ?? Theme.of(context).primaryColor, - size: widget.itemSize, + size: GFSizesClass.getGFSize(widget.size), ); } return GestureDetector( onTap: () { - if (widget.onRatingChanged != null) { - widget.onRatingChanged(index + 1.0); + if (widget.onChanged != null) { + widget.onChanged(index + 1.0); } }, onHorizontalDragUpdate: (dragDetails) { final RenderBox box = context.findRenderObject(); final _pos = box.globalToLocal(dragDetails.globalPosition); - final i = _pos.dx / widget.itemSize; + final i = _pos.dx / GFSizesClass.getGFSize(widget.size); var newRating = widget.allowHalfRating ? i : i.round().toDouble(); if (newRating > widget.itemCount) { newRating = widget.itemCount.toDouble(); @@ -127,8 +128,8 @@ class _GFRatingState extends State { if (newRating < 0) { newRating = 0.0; } - if (widget.onRatingChanged != null) { - widget.onRatingChanged(newRating); + if (widget.onChanged != null) { + widget.onChanged(newRating); } }, child: icon, @@ -136,13 +137,13 @@ class _GFRatingState extends State { } @override - Widget build(BuildContext context) => widget.textFormRating + Widget build(BuildContext context) => widget.textForm ? Column(children: [ Container( margin: widget.margin, padding: widget.padding, child: TextFormField( - controller: widget.ratingController, + controller: widget.controller, keyboardType: TextInputType.number, decoration: widget.inputDecorations == null ? InputDecoration( diff --git a/lib/types/gf_loader_type.dart b/lib/types/gf_loader_type.dart index 46c46817..3d58cf3e 100644 --- a/lib/types/gf_loader_type.dart +++ b/lib/types/gf_loader_type.dart @@ -1,3 +1 @@ -enum LoaderDotType { - square, circle, diamond, icon -} \ No newline at end of file +enum LoaderDotType { square, circle, diamond, icon }