How Sliding Images on next page Like Mob gallery - flutter

enter image description hereplz helpp me here i'm new to flutter....! i have seen many tutorials on this but nothig is happen to me...! what i want is i have listing array for gridview images and then ontap button the images shows to next screen ! in that i want sliding images like page is navigating and my images is sliding with same array which shows me above code on my 1st screen ! plz give me some tip on sliding images with same array of this page....! thank you for ua time..
plz give me some coding tips on next screen which i can slide images with same array
return Scaffold(
appBar: getAppBar(),
body: FutureBuilder(
future: _doctorsFuture,
builder: (context, projectSnap) {
Map data = projectSnap.data;
print(projectSnap);
if (projectSnap.connectionState == ConnectionState.none &&
projectSnap.hasData == null) {
return Center(
child: Text(
"Failed to loaed",
style: TextStyle(fontSize: 16.0, color: Colors.red),
));
} else if (projectSnap.hasData) {
return StaggeredGridView.countBuilder(
crossAxisCount: 2,
primary: false,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
itemCount: (data["hits"] as List).length,
itemBuilder: (context, index) {
if (_selectionMode) {
return GridTile(
header: GridTileBar(
trailing: Icon(
_selectedIndexList.contains(index) ? Icons
.check_circle_outline : Icons
.radio_button_unchecked,
color: _selectedIndexList.contains(index) ? Colors
.green : Colors.black,
),
),
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
color: Colors.transparent,
),
child:Image.network(
data['hits'][index]['largeImageURL'],
height: 50,
width: 100,
fit: BoxFit.cover,
)
),
onLongPress: () {
_changeSelection(enable: false, index: -1);
},
onTap: () {
setState(() {
if (_selectedIndexList.contains(index)) {
_selectedIndexList.remove(index);
} else {
_selectedIndexList.add(index);
}
});
},
),
);
}
else {
return GridTile(
child: InkResponse(
child: Image.network(
data['hits'][index]['largeImageURL'],
height: 50,
width: 100,
fit: BoxFit.cover,
),
onLongPress: () {
setState(() {
_changeSelection(enable: true, index: index);
});
},
onTap:(){
Navigator.of(context).push(MaterialPageRoute(builder: (context) => ImageView( imgPath: data['hits'][index]['largeImageURL'],)));
},
),
);
}
},
staggeredTileBuilder: (int index) => StaggeredTile.count(1, index.isEven ? 1.2 : 1.8),
padding: const EdgeInsets.all(4.0),
);
} else {
return Center(child: CircularProgressIndicator());
}
}
),
);
}

Related

FLUTTER UI Selection box (with Container and SetState) selected but nothing happen

Halo,
I have problem with my Selected Container,
it changed on main page when selected, but didn't change when selected in bottomsheet.
here's the video link :
https://youtube.com/shorts/hzPNNQB6Gws?feature=share
here is the screenshoot :
This is how I call in bottomsheet :
bottomsheet: Container(
~~
~~
child: OutlinedButton(
child: Text("Buy Now"),
onPressed: (){
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return bottomContainer(context);
});
},
),
)
here's the bottomContainer widget code :
Widget bottomContainer(BuildContext context) {
~~
~~
return Wrap(
spacing: 8.0,
runSpacing: 4.0,
children: <Widget> [
...List.generate(
listVariant.length,
(index) => selectedButton(
index: index,
text: listVariant[index],
),
),
],
),
~~
~~
}
and here's selectedButton widget full code :
Widget selectedButton({required String text, required int index}) {
return InkWell(
splashColor: Colors.cyanAccent,
onTap: () {
setState(() {
_selectedVariant = index;
print('$index, $text');
});
},
child: Container(
height: 36,
width: text.length.toDouble() *9,
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10)),
border: Border.all(
width: 1.5,
color: const Color.fromRGBO(78, 125, 150, 1),
),
color: index == _selectedVariant
? const Color.fromRGBO(78, 125, 150, 0.5)
: Colors.white,
),
child: Center(
child: Text(text,
textAlign: TextAlign.center,
style: const TextStyle(
color: Color.fromRGBO(78, 125, 150, 1),
fontSize: 13,
fontWeight: FontWeight.w700
),
),
)
),
);
}
IDK where's the problem because you can see in video that it was working on body, but didn't work in bottomsheet widget.
*All of this code was in one class state
The reason this is happening is that you try to update your main page not your showModalBottomSheet, first change your selectedButton to this:
Widget selectedButton({required String text, required int index, required Function() onTap}) {
return InkWell(
splashColor: Colors.cyanAccent,
onTap: onTap,
child: ...
);
}
then change your bottomContainer to this:
Widget bottomContainer(BuildContext context, void Function(void Function()) innerSetState) {
~~
~~
return Wrap(
spacing: 8.0,
runSpacing: 4.0,
children: <Widget> [
...List.generate(
listVariant.length,
(index) => selectedButton(
onTap:(){
innerSetState(() {
_selectedVariant = index;
});
},
index: index,
text: listVariant[index],
),
),
],
),
~~
~~
}
then change your showModalBottomSheet to this:
onPressed: (){
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, innerSetState) {
return bottomContainer(context, innerSetState);
},
),
});
},
Note: when you try to call selectedButton from your main page remember to pass these function to it:
selectedButton(
onTap:(){
setState(() {
_selectedVariant = index;
});
},
...
)

Updating list in memory doesn't change UI in Flutter

I am currently modifying my app to support large devices. In this app I want to have a list of categories at the left and when I tap the list tile I want to show the list of the items which the category holds on the left. By the approach I am using the list updates in memory but doesnt change the UI. This is my current approach ->
class _OrderCategoryScreenState extends State<OrderCategoryScreen> {
List<FoodItem> filteredLists = [];
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Row(
children: [
ValueListenableBuilder<Box<FoodCategory>>(
valueListenable: Boxes.getFoodCategories().listenable(),
builder: (context, box, child) {
final categories = box.values.toList().cast<FoodCategory>();
return categories.length == 0
? Container(
color: Color(0xFFFCF9F9),
height: double.infinity,
width: MediaQuery.of(context).size.height * 0.30,
child: Center(
child: Text("No Categories"),
))
: Container(
height: double.infinity,
width: MediaQuery.of(context).size.height * 0.35,
child: Drawer(
backgroundColor: Color(0xFFFCF9F9),
elevation: 0,
child: ListView(
children: <Widget>[
DrawerHeader(
child: ListView(
children: [
Container(
height: MediaQuery.of(context).size.height,
child: ValueListenableBuilder<
Box<FoodCategory>>(
builder: (context, value, child) {
final foodCategories = box.values
.toList()
.cast<FoodCategory>();
return ListView.builder(
itemCount: foodCategories.length,
itemBuilder: (context, index) {
return ListTile(
tileColor: Colors.green,
onTap: () {
filteredLists = Boxes
.getFoodItems()
.values
.where((element) =>
element.categoryName ==
foodCategories[index]
.name)
.toList();
print(filteredLists.length);
print("object");
},
title: Text(
foodCategories[index].name),
);
},
);
},
valueListenable: Boxes.getFoodCategories()
.listenable(),
),
)
],
),
),
],
),
));
},
),
Container(
width: MediaQuery.of(context).size.width * 0.5,
height: MediaQuery.of(context).size.height * 0.5,
color: Colors.amberAccent,
child: filteredLists.isEmpty
? Center(
child: Text("Choose A Category"),
)
: ListView.builder(itemCount: filteredLists.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(filteredLists[index].itemName),
);
},
),
),
],
)
),
);
}
}
When I hot reload using this approach it works on the UI as well.
Please Help.
Try calling setState to update the UI.
onTap: () {
filteredLists = Boxes
.getFoodItems()
.values
.where((element) =>
element.categoryName ==
foodCategories[index]
.name)
.toList();
print(filteredLists.length);
print("object");
setState((){}); //this
},

Flutter > Unselect a RadioButton in a View.builder

I am not finding any answer for my question so I am hoping to find someone who can help.
I have a GridView with text buttons.
I can select the buttons, however I can't unselect any of them.
this is my code
#override
Widget build(BuildContext context) {
return TextButton(
onLongPress: () => showDialog<String>(
),
style: ButtonStyle(
side: MaterialStateProperty.all(BorderSide(
width: 5,
color: widget.isSelected ? Colors.black : Colors.white)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10))),
backgroundColor: MaterialStateProperty.all(widget.pickerColor),
elevation: MaterialStateProperty.all(10)),
onPressed: () {
widget.selectedCard(widget.index); //This selects the cards, how to unselect (if Statements?)
},
child: FittedBox(
fit: BoxFit.fitHeight,
child: Text(
widget.cardTitle,
style: TextStyle(
fontSize: 17,
color: useWhiteForeground(widget.pickerColor)
? const Color(0xffffffff)
: const Color(0xff000000),
),
),
),
);
}
}
This is the Grid
#override
Widget build(BuildContext context) {
return Consumer<MyCardData>(
builder: (context, cardData, child) {
return Padding(
padding: const EdgeInsets.all(10),
child: GridView.builder(
clipBehavior: Clip.none,
itemBuilder: (context, index) {
final card = cardData.cards[index];
return MyCard(
selectedCard,
index: index,
isSelected: _selectedCard == index,
cardTitle: card.name,
pickerColor: card.cardColor,
deleteCallback: () {
cardData.deleteCallback(card);
},
);
},
itemCount: cardData.cardCount,
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 150,
childAspectRatio: 2.5 / 1,
crossAxisSpacing: 0,
mainAxisSpacing: 0,
),
),
);
},
);
}
}
feel free to use my git to see the full code
get from version control
since you want to make a single selection, it will need a simple workaround.
int _selectedCard = -1;
selectedCard(index) {
// this condition is when user press the same button
// set the _selectedCard back into -1
if (_selectedCard == index) {
setState(() {
_selectedCard = -1;
});
} else{
setState(() {
_selectedCard = index;
});
}
}

Problem with ListView that located over Google map in Flutter web

I'm trying to implement page with Google map and i put ListView over this map. When i scroll this vertical ListView, map is actually scrolls too. Is there any way to prevent this behaviour and scroll map only when cursor located out of listview boundaries? Thanks[![Scroll conflict behind listview and google map][1]][1]
/// Layout that describes part with ListView
Positioned.fill(
child: Align(
alignment: Alignment.bottomRight,
child: sessions.maybeWhen(
orElse: () => const SizedBox.shrink(),
data: (items) {
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: items.length <= 3
? items.length * 130
: mediaQuery.size.width < 720 ? 150 : mediaQuery.size.height * 0.7,
),
child: ScrollablePositionedList.separated(
itemScrollController: controller,
scrollDirection: mediaQuery.size.width < 720
? Axis.horizontal
: Axis.vertical,
padding: EdgeInsets.all(mediaQuery.size.width < 720 ? 5 : 20.0),
itemCount: items.length,
separatorBuilder: (_, __) => mediaQuery.size.width < 720
? const SizedBox(width: 6.0)
: const SizedBox(height: 6.0),
itemBuilder: (_, i) {
return AdaptiveLayout(
smallLayout: Align(
alignment: Alignment.bottomCenter,
child: SizedBox(
width: mediaQuery.size.width - 32,
height: 100.0,
child: SessionCard(
session: items[i],
selected: selected == items[i],
onPressed: () {
if (selected == items[i]) {
onSelected?.call(null, null);
} else {
onSelected?.call(items[i], i);
}
},
),
),
),
largeLayout: FractionallySizedBox(
widthFactor: 0.4,
alignment: Alignment.bottomRight,
child: SessionCard(
session: items[i],
selected: selected == items[i],
onPressed: () {
if (selected == items[i]) {
onSelected?.call(null, null);
} else {
onSelected?.call(items[i], i);
}
},
),
),
);
},
),
);
},
),
),
);
///Part with Stack that contains map and ListView
AdaptiveLayout(
smallLayout: Scaffold(
body: Stack(
children: [
MapWidget(
onMapCreated: onMapCreated,
onMarkerSelected: onSessionSelected,
),
// const SearchBar(),
MapToolbar(
controller: mapController.value,
handlePermission: () async {
final provider = ref.read(positionProvider.notifier);
if (await (provider.handlePermission(context))) {
provider.getCurrentLocation();
}
},
),
ValueListenableBuilder<dynamic>(
valueListenable: selectedSession, /// Contains ListView
builder: (_, value, __) {
return SessionCards(
onSelected: onSessionSelected,
selected: value,
controller: scrollController.value,
);
},
),
ValueListenableBuilder<bool>(
valueListenable: showLoading,
builder: (_, value, __) {
return LoadingOverlay(
showing: value,
);
},
),
],
),
),

Problem pageview reload first page after setState ( Flutter )

I have a code, this code create a pageview about some user, data is get from firebase
return new Scaffold(
appBar: new AppBar(
title: new Text("Carousel"),
),
body: StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('users').snapshots(),
builder:
(BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) return new Text('Error: ${snapshot.error}');
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return new CircularProgressIndicator();
default:
return new PageView(
onPageChanged: _onPageViewChange,
controller: _controller,
scrollDirection: Axis.horizontal,
children:
snapshot.data.documents.map((DocumentSnapshot document) {
return new Column(
children: <Widget>[
new Container(
child: new ClipOval(
child: new CachedNetworkImage(
width: 150.0,
height: 150.0,
imageUrl: document['img'],
fit: BoxFit.fill,
placeholder: (context, url) =>
CircularProgressIndicator(),
errorWidget: (context, url, error) =>
Icon(Icons.error),
)),
),
new ListTile(
title: new Text(
isPerson
? 'My name is'
: (isPlace
? 'My favourite is'
: (isNote
? 'I am from'
: (isPhone
? 'My phone is'
: (isLock ? '' : '')))),
textAlign: TextAlign.center),
subtitle: new Text(
isPerson
? document['name']
: (isPlace
? document['place']
: (isNote
? document['note']
: (isPhone
? document['phone']
: (isLock
? document['lock'].toString()
: "")))),
textAlign: TextAlign.center,
),
),
buildButton1(Icons.person)
],
);
}).toList(),
);
}
},
));
}
this is fuction buildButton1()
Widget buildButton1(IconData icon) {
return new Column(
children: <Widget>[
new Container(
padding: EdgeInsets.only(left: 10.0, right: 10.0, top: 20.0),
child: new IconButton(
icon: Icon(icon),
onPressed: () {
setState(() {
//isChecked ? true : false;
isPerson = true;
isNote = false;
isPlace = false;
isPhone = false;
isLock = false;
});
},
iconSize: 32.0,
color: isPerson ? Colors.green : Colors.grey,
),
)
],
);
}
When I press a button to set variable then Pageview reload and show firstpage. How can I solved this problem. This is example picture https://imgur.com/nKC358E
................................................................................................
The issue comes from the _onPageViewChange function.
The last page doesn't return an integer value. If you have 3 pages, than the last returned index will be 1.99999999999... and not 2.
I solved the problem like this
onPageChanged: (index){
setState(() {
if (index > 1.99){
lastPage=true;
}else{
lastPage=false;
}
});
}