Adding next and previous buttons to a ListView in flutter - flutter

I was converting the following below ui to code.
I didn't find a suitable package for it, im stepper also didn't have the ability to customize in this way.
So I tried to use listView.builder.
Now I don't know how to add the next and previous buttons.
so that the number inside the scroll view scrolls like the picture below and is placed in the view area.
If you know a suitable package, introduce it.
my code:
FadingEdgeScrollView.fromScrollView(
gradientFractionOnEnd: 0.2,
gradientFractionOnStart: 0.15,
child: ListView.builder(
controller: _controller2,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
int one = index + 1;
int two = 0;
Color colorWhat(int q) {
Color color;
if (q == two) {
color = Color(0xff0AFF6C);
} else {
color = Colors.white;
}
return color;
}
double sizeOfCircle(int qq) {
int size;
if (qq == 0) {
size = 27;
} else {
size = 22;
}
return size.toDouble();
}
double sizeOfCircleText(int qqq) {
double size;
if (qqq < 10) {
size = 13.9;
} else {
size = 13.7;
}
return size;
}
return GestureDetector(
child: Row(
children: [
Container(
alignment: Alignment.center,
width: sizeOfCircle(index),
// height: sizeOfCircle(index),
// padding: EdgeInsets.all(sizeOfCircle(index)),
margin: const EdgeInsets.fromLTRB(
2, 0, 17, 0),
decoration: BoxDecoration(
color: colorWhat(index),
shape: BoxShape.circle,
boxShadow: const [
BoxShadow(
offset: Offset(0, 5),
blurRadius: 10.0,
spreadRadius: -7,
),
],
),
child: Text(
one.toString(),
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: sizeOfCircleText(index),
),
),
),
],
),
onTap: () =>
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text((index+1).toString()),
),
),
);
},
itemCount: 100,
),
),

first select a current index like this:
int currentPageIndex = 0;
and then on tap function. Write a code like this
for decrement...
if (currentPageIndex == 4) {
return;
}
setState(() {
currentPageIndex += 1;
});
for Increment...
if (currentPageIndex == 4) {
return;
}
setState(() {
currentPageIndex += 1;
});
Change your text...
Text(
'${index + 1}'
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: sizeOfCircleText(index),
),
),
and change your onTap function like this:
onTap: () {
setState(() {
currentPageIndex = index;
});
},

Related

Refreshing ListView.builder with ToggleButton flutter

Basically, I'm trying to make an app, that on one of the screens - the content of a listview will be updated by choosing one of the options listed in the toggleButtons (One shows only upcoming events and the second option is events that have been passed). But when I try to set the new state, it doesn't reload the listview and doesn't colour the selected option in the ToggleButtons. How can I refresh both?
For reference:
List filteredCands = []; //Starts empty, gets filled with events when clicking one of the buttons
List isSelected = [true, false];
ToggleButtons and setState(():
child: ToggleButtons(
isSelected: isSelected,
selectedColor: Colors.white,
color: Color(0xFF33CCCC),
fillColor: Color(0xFF33CCCC),
renderBorder: true,
borderWidth: 1.5,
borderRadius: BorderRadius.circular(10),
children: const [
Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: Icon(FontAwesomeIcons.calendarXmark, size: 25),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: Icon(FontAwesomeIcons.calendarDay, size: 25),
),
],
onPressed: (int newIndex) {
final data = listViewGetCandListByManagerResponse
.jsonBody['candList'] as List;
List<CandModel> cands = data.map((e) => CandModel.fromJson(e))
.toList();
DateTime now = new DateTime.now();
DateTime currentDate = new DateTime(now.year, now.month, now.day);
setState(() {
//looping through the list of bool values
for (int index = 0; index < isSelected.length; index++)
{
//Checking for the index value
if (index == newIndex)
{
isSelected[index] = true;
if (index == 0)
{
for (var i = 0; i < cands.length; i++) {
DateTime expirationDate = DateTime.parse(cands[i].dateEvent);
final bool isExpired = expirationDate.isBefore(currentDate);
if (isExpired == true) {
filteredCands.add(cands[i]);
}
}
}
if (index == 1)
{
for (var i = 0; i < cands.length; i++) {
DateTime expirationDate = DateTime.parse(cands[i].dateEvent);
final bool isFuture = currentDate.isBefore(expirationDate);
if (isFuture == true) {
filteredCands.add(cands[i]);
}
}
}
}
else
{isSelected[index] = false;}
}
});
},
),
That's the ListView:
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 8, 0, 0),
child: FutureBuilder<ApiCallResponse>(
future: GetCandListByManagerCall.call(
entityId: widget.entityId,
),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: SizedBox(
width: 50,
height: 50,
child: CircularProgressIndicator(
color:
FlutterFlowTheme.of(context).primaryColor,
),
),
);
}
return Builder(
builder: (context) {
if (filteredCands.isEmpty) {
return Center(
child: Text('Error - Looks like there are no events available'
),
);
}
return ListView.builder(
padding: EdgeInsets.zero,
scrollDirection: Axis.vertical,
itemCount: filteredCands.length,
itemBuilder: (context, dataIndex) {
if (!snapshot.hasData) {
return Center(
child: SizedBox(
width: 50,
height: 50,
child: CircularProgressIndicator(
color: FlutterFlowTheme.of(context).primaryColor,
),
),
);
}
int count = 0;
String date = (filteredCands[dataIndex].dateEvent).toString();
DateTime tempDate = DateTime.parse(date);
String dmy = DateFormat.yMMMd().format(tempDate);
String exDate = dmy; //Date Formatting
return InkWell(
child: SworkerContainerWidget(
desc: filteredCands[dataIndex].descEvent,
fname: filteredCands[dataIndex].wfirstName,
lname: filteredCands[dataIndex].wlastName,
dateEvent: exDate,
),
);
},
);
},
);
And the results:
As you can see, I'm clicking the 2nd option and it doesn't colour it nor refreshing the listview
Check where you first declared on your list. this might be the cause of the problem (found out I misplaced it) it need to go under class __widgetstate and not under builder.
Also would recommend to clear the listview everytime the button gets clicked, unless you want infinite events on your list haha

Why does the Gridview.builder overflow? (Flutter/Dart)

I have been trying to fix this bug without success. I am trying to make a Gridview.builder widget that will hold the buttons for a calculator. I want the widget to fit on the lower part of the screen without overflowing. I tried to fix it by wrapping a Gridview into a Contianer or a ConstrainedBox with a certain height and width. However, the Gridview still keeps overflowing.
Here is my code for the Gridview:
Expanded(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: ScreenHeight(context) * .3,
maxHeight: ScreenHeight(context) * .4,
),
child: Container(
margin: EdgeInsets.only(
right: ScreenHeight(context) * .02,
left: ScreenHeight(context) * .02),
child: GridView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: buttons.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: getCrossAxisCount(context)),
itemBuilder: (BuildContext context, int index) {
// Clear Button
if (index == 0) {
return CalcButton(
onTap: () {
setState(() {
userInput = '';
calcAnswer = '';
});
},
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// +/- button
else if (index == 1) {
return CalcButton(
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// % Button
else if (index == 2) {
return CalcButton(
onTap: () {
setState(() {
userInput += buttons[index];
});
},
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// Delete Button
else if (index == 3) {
return CalcButton(
onTap: () {
setState(() {
userInput = userInput.substring(
0, userInput.length - 1);
});
},
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// Equal_to Button
else if (index == 18) {
return CalcButton(
onTap: () {
setState(() {
equalPressed();
});
},
buttonText: buttons[index],
color: Colors.orange[700],
textColor: Colors.white,
);
}
// other buttons
else {
return CalcButton(
onTap: () {
setState(() {
userInput += buttons[index];
});
},
buttonText: buttons[index],
color: isOperator(buttons[index])
? Colors.blueAccent
: Colors.white,
textColor: isOperator(buttons[index])
? Colors.white
: Colors.black,
);
}
},
),
),
),
),
Here is my code for CalcButton:
class CalcButton extends StatelessWidget {
final color;
final textColor;
final String buttonText;
final onTap;
CalcButton({
this.color,
this.textColor,
this.buttonText = "",
this.onTap,
});
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Padding(
padding: EdgeInsets.all(.3),
child: ClipRRect(
child: Container(
color: getCalcButtonColor(calcTheme,
buttonText), //gets calc button color from created method
child: Center(
child: Text(
buttonText,
style: TextStyle(
color: getButtonTxtColor(calcTheme,
buttonText), //gets button txt color from created method
fontSize: ScreenWidth(context) * .05,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
);
}
}
Here is how it looks:
Image 1
Image 2
Note that the ScreenHeight() and ScreenWidth() functions are functions that return the value of MediaQuery.of(context).size.width and MediaQuery.of(context).size.height
I have also tried to remove Expanded() and only use a ConstrainedBox, but the same thing still happens.
Any help will be much appreciated.

Flutter : how to show next index after complete a specific logic in Swiper, where GridView also set in Swiper?

I'm trying to make a word game. First of all, the index will be white. if user Click the correct answer then index will be to green color and go to next screen, also index will be white in next screen.. again if user click incorrect answer then index will be to red color and don't let go to the next page until user put correct answer...
i set a GridView in Swiper (Swiper took by importing,
import 'package:flutter_swiper/flutter_swiper.dart';).
and i want to show next index of Swiper after completing a logic in GridView. suppose, i have a long string list(array) and took four value string from this list(array) by random, this four values string set in GridView index.
Again i make a new string list(array) by this four value string and took a value from this new string list(array) by random, this single string set in Swiper. finally if user can select the Swiper index value to the GridView four index value correctly, then user can see next screen in Swiper. but output is not working properly. problem is - at first i set white color in GridView index, if it is correct answer should be green color in GridView index and incorrect will be red color in GridView index. here is my logic made it messy.
import 'package:flutter_swiper/flutter_swiper.dart';
import 'dart:math';
class GameWordRoute extends StatefulWidget {
#override
_GameWordRouteState createState() => _GameWordRouteState(); }
class _GameWordRouteState extends State<GameWordRoute> {
SwiperController _controller = SwiperController();
SwiperControl _control = SwiperControl(color: Colors.white);
double get _width => MediaQuery.of(context).size.width;
double get _height => MediaQuery.of(context).size.height;
bool inLastPage = true;
bool _answer = false;
List<Color> colorList = <Color>[Colors.white, Colors.white, Colors.white, Colors.white,];
List<String> gameButtonList = <String>[];
FlutterTts flutterTts = FlutterTts();
#override
Widget build(BuildContext context) {
var sizeDevice = MediaQuery.of(context).size;
final orientation = MediaQuery.of(context).orientation;
final double itemHeight = sizeDevice.width / 6;
final double itemWidth = sizeDevice.width / 2;
return Scaffold(
backgroundColor: Colors.purple, // white
body: SafeArea(
child: Column(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
color: Colors.lightBlueAccent,
)),
Expanded(
flex: 8,
child: Container(
color: Colors.cyan,
child: Swiper(
controller: _controller,
loop: false,
scrollDirection: Axis.horizontal,
itemCount: word_data.drink.length,
onIndexChanged: (value) {
if (value == word_data.drink.length - 1)
setState(() {
inLastPage = true;
});
else {
setState(() {
inLastPage = true; // false
});
}
},
itemBuilder: (BuildContext context, int index) {
gameButtonList.clear();
var fourValueRandom = new Random();
for (var i = 0; i < 4; i++) {
final fourGameBtnRandom = word_data.drink[fourValueRandom.nextInt(word_data.drink.length)];
gameButtonList.add(fourGameBtnRandom);
}
var oneValueRandom = new Random();
var oneValueRandomGet = gameButtonList[oneValueRandom.nextInt(gameButtonList.length)];
var wordDataReplace = oneValueRandomGet.replaceAll(" ", "_").toLowerCase();
return Container(
child: Column(
children: <Widget>[
Expanded(
flex: 8,
child: Container(
color: Colors.purple,
width: _width,
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Image.asset("asset/drink_images/" + wordDataReplace + ".png",
fit: BoxFit.contain,
),
),
)),
Expanded(
flex: 1,
child: Container(
color: Colors.yellow,
width: _width,
alignment: Alignment.center,
// "${categoryTitleArray[index]}"
child: Text("What is this?"),
)),
Expanded(
flex: 4,
child: Container(
color: Colors.yellow[200],
width: _width,
alignment: Alignment.center,
child: GridView.builder(
padding: EdgeInsets.all(8),
itemCount: 4,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: (orientation == Orientation.portrait) ? 2 : 4,
crossAxisSpacing: 5,
mainAxisSpacing: 5,
childAspectRatio: (itemWidth / itemHeight),
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
if (index == 0) {
if (gameButtonList[0] == oneValueRandomGet){
_answer = true;
inLastPage = false;
colorList[0] = Colors.green;
setState((){});
_showCorrectAndIncorrectDialog("Congratulation", "asset/icon_images/ok_emoji.png", "Correct answer", Colors.green);
}else{
colorList[0] = Colors.red;
inLastPage = true;
setState((){});
}
} else if (index == 1) {
if (gameButtonList[1] == oneValueRandomGet){
_answer = true;
colorList[1] = Colors.green;
setState((){});
_showCorrectAndIncorrectDialog("Congratulation", "asset/icon_images/ok_emoji.png", "Correct answer", Colors.green);
inLastPage = false;
}else{
colorList[1] = Colors.red;
inLastPage = true;
setState((){});
}
} else if (index == 2) {
if (gameButtonList[2] == oneValueRandomGet){
_answer = true;
colorList[2] = Colors.green;
setState((){});
_showCorrectAndIncorrectDialog("Congratulation", "asset/icon_images/ok_emoji.png", "Correct answer", Colors.green);
inLastPage = false;
}else{
colorList[2] = Colors.red;
inLastPage = true;
setState((){});
}
} else if (index == 3) {
if (gameButtonList[3] == oneValueRandomGet){
_answer = true;
colorList[3] = Colors.green;
inLastPage = false;
setState((){});
_showCorrectAndIncorrectDialog("Congratulation", "asset/icon_images/ok_emoji.png", "Correct answer", Colors.green);
}else{
colorList[3] = Colors.red;
inLastPage = true;
setState((){});
}
}
},
child: Container(
child: new Card(
elevation: 0,
color: colorList[index], //Colors.transparent,
child: Center(
child: Text(
"${gameButtonList[index]}",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.black),
),
),
),
),
);
}),
)),
],
),
);
},
),
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.lightBlueAccent,
)),
],
),
),
);
}
void _showCorrectAndIncorrectDialog(String _title, String _image, String _subTitle, Color _color){
showDialog(
context: context,
builder: (BuildContext context){
Future.delayed(Duration(milliseconds: 500), () {
Navigator.of(context).pop(true);
});
return AlertDialog(
title: Text(_title, textAlign: TextAlign.center, style: TextStyle(color: _color),),
content: Container(
height: _width/1.1,
child: Column(
children: <Widget>[
Expanded(
flex: 4,
child: Container(
// color: Colors.cyan[100],
child: Image.asset(_image,
fit: BoxFit.cover,
),
),
),
SizedBox(height: 8),
Expanded(
flex: 1,
child: Container(
color: Colors.cyan,
child: Center(
child: Text(
_subTitle,
style: TextStyle(
// fontSize: 24,
),
),
),
),
),
],
),
),
);
}
);
}
}
so first thing you should do is changing your onTap function in your gesture detector into a simpler code You shouldn't verify every single number for the index because the index is already that number
To be more clear when you call list[index] the index here is an integer so if the index==1 you're calling list[1] and if the index==5 you're calling list[5] you don't have to test if index==1 or something like that
so your code should be something like this
onTap: () async{
if (gameButtonList[index] == oneValueRandomGet){
_answer = true;
colorList[index] = Colors.green;
inLastPage = false;
setState((){});
_showCorrectAndIncorrectDialog("Congratulation", "asset/icon_images/ok_emoji.png", "Correct answer", Colors.green);
}else{
colorList[index] = Colors.red;
inLastPage = true;
setState((){});
}
},
And next for the problem of testing if the answer is correct or not and color changing and going to next screen
First thing please move these lines in your item builder function into a function you can call from anywhere like this for example
void newQuestion(){
gameButtonList.clear();
var fourValueRandom = new Random();
for (var i = 0; i < 4; i++) {
final fourGameBtnRandom = word_data.drink[fourValueRandom.nextInt(word_data.drink.length)];
gameButtonList.add(fourGameBtnRandom);
}
oneValueRandomGet = gameButtonList[fourValueRandom.nextInt(gameButtonList.length)];
wordDataReplace = oneValueRandomGet.replaceAll(" ", "_").toLowerCase();
}
and you can call this question after calling your dialogAlert if you change the line when you call _showCorrectAndIncorrectDialog(...) into
_showCorrectAndIncorrectDialog("Congratulation", "asset/icon_images/ok_emoji.png", "Correct answer", Colors.green);
newQuestion() //**Add this line also**
Notes :
-Remember to declare the variables you need in your class so they get changed in newQuestion function
-First time you lunch the app the variables like " oneValueRandomGet " are gonna be null so you can't show any data, call oneQuestion() in your initState so that when launching the app you get your first question ready directly.
I hope all this doesn't confuse you I tried my best to simplify and give you the simplest edit and answer possible, please if you're still unable to fix your problem I would really advice you to try to rewrite your code and try to make it as simple as possible.
Thank you.

How do i set the value of toggle buttons within teams?

How do i set the value of the toggle score buttons for each team ?
For example when team A is pressed then user can choose from score buttons. Also if team B is pressed then user can choose from score buttons. But only the team selected gets the points.
void scoreTeamA() {
setState(() {
outputTeamA += _choiceA;
});
}
void scoreTeamB() {
setState(() {
outputTeamB += _choiceB;
});
}
Team buttons
ToggleButtons(
children: [
Container(
child: Text(
'team A',
textScaleFactor: 3,
),
),
Text(
'team B ',
textScaleFactor: 3,
),
],
onPressed: (int index) {
setState(() {
for (int buttonIndex = 0;
buttonIndex < isSelected1.length;
buttonIndex++) {
if (buttonIndex == index) {
isSelected1[buttonIndex] = true;
} else {
isSelected1[buttonIndex] = false;
}
}
});
},
Score buttons
ToggleButtons(
children: [
Text('5 points'),
Text('6 points'),
Text('7 points'),
],
onPressed: (int index) {
setState(() {
isSelected2[index] = !isSelected2[index];
switch (index) {
case 0:
_choiceA = 5;
_choiceB = 5;
break;
case 1:
_choiceA = 6;
_choiceB = 6;
break;
case 2:
_choiceA = 7;
_choiceB = 7;
break;
}
});
},
isSelected: isSelected2,
),
Win Button
MaterialButton(
shape: CircleBorder(
side: BorderSide(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid)),
color: Colors.blue,
onPressed: () {
setState(() {
scoreTeamA();
scoreTeamB();
});
},
child: Text(
'win',
textScaleFactor: 3,
),
),
Okay I believe this is what you are looking for I want to explain some things because I ended up having to change a little bit more than what your question asked because other problems presented themselves once i got the logic you wanted working so here is the code.
Also sorry about the extra styling you can take it out.
int outputTeamA = 0;
int outputTeamB = 0;
List<bool> isSelected1 = [false, false];
List<bool> isSelected2 = [false, false, false];
int _choiceA = 0;
int _choiceB = 0;
void scoreTeamA() {
setState(() {
outputTeamA += _choiceA;
});
}
void scoreTeamB() {
setState(() {
outputTeamB += _choiceB;
});
}
#override
Widget build(BuildContext context) {
ToggleButtons toggleButtons = ToggleButtons(
borderRadius: BorderRadius.circular(30),
borderColor: Colors.pink,
children: [
Container(
padding: EdgeInsets.all(8.0),
child: Text(
'Team A',
textScaleFactor: 3,
),
),
Text(
'Team B ',
textScaleFactor: 3,
),
],
onPressed: (int index) {
setState(
() {
for (int buttonIndex = 0;
buttonIndex < isSelected1.length;
buttonIndex++) {
if (buttonIndex == index) {
isSelected1[buttonIndex] = true;
} else {
isSelected1[buttonIndex] = false;
}
}
},
);
},
isSelected: isSelected1,
);
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
toggleButtons,
SizedBox(height: 20),
ToggleButtons(
borderColor: Colors.pink,
borderRadius: BorderRadius.circular(30),
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('5 points'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('6 points'),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('7 points'),
),
],
onPressed: (int index) {
setState(() {
isSelected2[index] = !isSelected2[index];
switch (index) {
//This is the other area I had to make changes
case 0:
if (isSelected2[index]) {
print('true');
_choiceA += 5;
_choiceB += 5;
} else {
print('false');
_choiceA += -5;
_choiceB += -5;
}
break;
case 1:
if (isSelected2[index]) {
_choiceA += 6;
_choiceB += 6;
} else {
_choiceA += -6;
_choiceB += -6;
}
break;
case 2:
if (isSelected2[index]) {
_choiceA += 7;
_choiceB += 7;
break;
} else {
_choiceA += -7;
_choiceB += -7;
break;
}
}
});
},
isSelected: isSelected2,
),
SizedBox(height: 20),
MaterialButton(
shape: CircleBorder(
side: BorderSide(
color: Colors.black,
width: 1.0,
style: BorderStyle.solid)),
color: Colors.blue,
onPressed: () {
//This is the logic you wanted
if (isSelected1[0]) {
setState(() {
scoreTeamA();
});
} else if (isSelected1[1]) {
setState(() {
scoreTeamB();
});
}
print('TeamA: $outputTeamA');
print('TeamB: $outputTeamB');
},
child: Text(
'win',
textScaleFactor: 3,
),
),
],
)),
),
);
}
Once I added the logic you wanted I noticed that if the user selected and un-selected a score then pressed 'I Win' the app acted as though that score was still selected so thats why I made the other changes I made now I don't know if you want to allow more than one score to be selected at a time right now thats how you had the logic set up so thats the route I went. If this is not how you want it to work it shouldn't be that hard to switch some of this logic around. So in conclusion if multiple scores are selected they get added together.

ListView builder don't change in the required time

I have search method who it can detect element form map and put theme in List variable where my List view builder takes his elements from.
the problem when I insert my word in Text Filed , list view builder doesn't change her statement until I close the keyboard and then I can see the change.
I want to see elements who I search currently
this my code :
_showDialog(){
var searchList = [];
int _manyOfWidgetShow = 0;
double heightOfListView = 0;
double higNumber(){
double _number;
if(_manyOfWidgetShow == 0){
_number = 0.25;
}
else if(_manyOfWidgetShow == 1){
_number = 0.3;
}else if(_manyOfWidgetShow == 2){
_number = 0.5;
}else if(_manyOfWidgetShow == 3){
_number = 0.6;
}
return _number;
}
void _showSearchReturn(String query){
List _items = [];
if(query.isNotEmpty){
testList.forEach( (element){
if(element["name"].toString().toLowerCase().startsWith(query) && _items.length < 3){
_items.add(element);
}
else if(query.length >= 2 && element["name"].toString().toLowerCase().contains(query) && _items.length < 3){
_items.add(element);
}
}
);
setState(() {
_manyOfWidgetShow = _items.length;
if(_manyOfWidgetShow != 0) {
heightOfListView = _manyOfWidgetShow * 50.0;
}else{
heightOfListView = 0;
}
searchList.clear();
searchList.addAll(_items);
});
}else{
setState(() {
_manyOfWidgetShow = _items.length;
if(_manyOfWidgetShow != 0){
heightOfListView = _manyOfWidgetShow * 50.0;
}else{
heightOfListView = 0;
}
searchList.clear();
});
}
}
showDialog(
context: context,
builder: (BuildContext context){
var _size = MediaQuery.of(context).size;
return Container(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30)
),
child: Container(
height: _size.height * higNumber(),
child: Column(
children: <Widget>[
Card(
margin: EdgeInsets.only(top:20,bottom: 15),
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15)
),
child: Container(
alignment: Alignment.center,
padding: EdgeInsets.only(top: 15,bottom: 18),
child: TextField(
onChanged: (value){
_showSearchReturn(value);
},
scrollPadding: EdgeInsets.all(20),
autocorrect: false,
decoration: InputDecoration.collapsed(
hintText: "Movie name",
),
style: TextStyle(
fontSize: 20
),
strutStyle: StrutStyle(
fontWeight: FontWeight.bold,
height: 1.5
),
controller: searchText ,
cursorWidth: 2,
cursorColor: Color(0xff54C4A2),
textAlign: TextAlign.center,
),
)
),
Container(
height: heightOfListView,
child: ListView.builder(
itemCount: searchList.length,
shrinkWrap: true,
itemBuilder:(context,index){
return ItemInfo(searchList[index]["name"],searchList[index]["id"]);
}
)
),
Expanded(
child: Container(
alignment: Alignment.bottomLeft,
child: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black54,),
onPressed: (){
},
),
)
)
],
),
),
)
);
}
);
}