In Flutter, I want to move an image in a container into another container positioned another part of the screen with animation.
Which animation packages do I need to use to do this? Can you help me?
Best wishes...
When I click on one of the playing cards in the image, I want the card to be moved into the container in the center.
Use flutter_draggable_gridview: ^0.0.7
DraggableGridViewBuilder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width / (MediaQuery.of(context).size.height / 3),
),
children: _listOfDraggableGridItem,
isOnlyLongPress: false,
dragCompletion: (List<DraggableGridItem> list, int beforeIndex, int afterIndex) {
print( 'onDragAccept: $beforeIndex -> $afterIndex');
},
dragFeedback: (List<DraggableGridItem> list, int index) {
return Container(
child: list[index].child,
width: 200,
height: 150,
);
},
dragPlaceHolder: (List<DraggableGridItem> list, int index) {
return PlaceHolderWidget(
child: Container(
color: Colors.white,
),
);
},
);
Related
I want to achieve UI like Windows File Explorer
windows file explorer
Build one list as start and inside it a list of items and the item contains a title and a list of items
The image you attached looks like it could be replicated with a ListView.builder returning an ExpansionTile containing a GridView.
SizedBox(
height: 40,
width: 300,
child: ListView.builder(
itemBuilder: (context, index) {
return ExpansionTile(
title: const Text('title'),
children: [
SizedBox(
height: 100,
width: 200,
child: GridView.count(
crossAxisCount: 3,
children: List.generate(
3,
(index) {
return SizedBox(
height: MediaQuery.of(context).size.height / 1.8,
child: const Icon(Icons.folder),
);
},
),
),
),
],
);
},
),
);
This builds several expansion tiles each containing 3 folder icons. You may consider adding a little bit more to your question as it is a little vague, but I hope this helps!
I'm currently using a custom widget similar to this chips_input library. However, I don't want to give the options view (the popup list) a static maximum height. What I want to achieve is to dynamically set a maximum height of screen height - popup y offset. In this way, bottom of the options view will be at the bottom of the screen and all of the content inside the options view will be visible through scrolling. Is there any that I can access the textfield's or options view's offset to calculate the height?
My autocomplete widget looks similar to this:
RawAutocomplete<T>(
...
optionsViewBuilder: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: textFieldWidth,
child: Material(
elevation: 16,
child: ListView.builder(
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (BuildContext context, int index) {
final T option = options.elementAt(index);
return suggestionBuilder(context, option);
},
),
),
),
),
);
You can do this by putting a height on your SizedBox that uses MediaQuery to get the screen height:
popupOffset = 20;
RawAutocomplete<T>(
...
optionsViewBuilder: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: textFieldWidth,
height: MediaQuery.of(context).size.height - popupOffset,
child: Material(
elevation: 16,
child: ListView.builder(
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (BuildContext context, int index) {
final T option = options.elementAt(index);
return suggestionBuilder(context, option);
},
),
),
),
),
);
I am showing images on gridview but i have a problem. I want to make the image's height and width equal.
This is the picture and I want to make image on the right to the have same width and height like the left one.Or at least put a white cover to missing part.
This is my code:
child: Consumer<Images>(
builder: (ctx, titles, ch) => GridView.builder(
physics: ScrollPhysics(),
itemCount: titles.items.length,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: getSize(_currentSliderValue),
mainAxisSpacing: 50,
childAspectRatio: 115/162.05,
crossAxisSpacing: 5,
),
itemBuilder: (ctx, index) {
saveallimages(titles.items);
return GestureDetector(
onTap: () => add(titles.items[index].image),
//()=>add(titles.items[index].image),
child: selected.contains(titles
.items[index].image.path
.toString()) ?
Container(child: selectedimage(titles.items[index].image)) :
Container(child: nonselected(titles.items[index].image))
);
And this is my widget function:
Widget selectedimage(image) {
return Stack(children: <Widget>[
Image.file(image, fit: BoxFit.cover),
Positioned(
right: 12,
bottom: 10,
child: Image.asset("assets/images/selected.png", width: 26, height: 26),
)
]);
}
Widget nonselected(image) {
return Stack(children: <Widget>[
Image.file(image, fit: BoxFit.cover),
]);
}
selectedimage function is to put check icon when the image is selected.
Instead of use Image.file or Image.asset as a child you can try using AssetImage or FileImage inside Container decoration like :
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: FileImage(image),
fit: BoxFit.cover,
),
)
)
I have a problem with this layout. I have a menu button with 6 item and I use a grid for it( I disable the scroll function). When I try it in my Poco F1, it place right in the center of the screen. But when I use a phone with bigger screen, the menu is slightly in the left side of the screen. Is there any way to make it in the center of the screen despite different screen size?
Here is the picture when using Pixel 3 XL
This is my code
Widget _gridView (BuildContext context) {
double cardWidth = MediaQuery.of(context).size.width / 2;
double cardHeight = MediaQuery.of(context).size.height * 31/100;
return GridView.count(
shrinkWrap: true,
childAspectRatio: cardWidth / cardHeight,
crossAxisCount: 2,
scrollDirection: Axis.horizontal,
mainAxisSpacing: 5,
crossAxisSpacing: 3,
children: List.generate(6, (index) {
return
Center(
child: Container(
alignment: Alignment.center,
child:
SizedBox(
child: Column(
children: [
InkWell(
onTap: (){
if(index == 0)
Navigator.of(context).push(new MaterialPageRoute(builder: (context) => new DoctorList()));
if(index == 1)
launchWhatsApp();
if(index == 2)
launchWhatsApp();
if(index == 5)
showMenu(context);
},
child: Container(
width: 80,
height: 80,
child: Image.asset(icons[index]),
),
),
SizedBox(
height: 5,
),
Text(teks[index], style: TextStyle(color: Colors.black, fontSize:14, fontWeight: FontWeight.bold),)
],
)
)
),
);
})
);
}
you can use flutter screen util package and give dimension using it,
it will give dimension according to device aspect ratio
I am making a reader app and I have a ListView.builder which is loading multiple Images from the API. Now I want to add a layer on top of the ListView with 2 transparent containers so that when I click the left container the list goes up and when I click the right container the list goes down. I tried adding the ListView to stack but then the scrolling ability of the list is gone. This is my code so far:
return Scaffold(
body: Stack(
children: [
ListView.builder(
controller: _scrollViewController,
cacheExtent: 1000,
itemCount: _picLinkMap.length,
itemBuilder: (BuildContext ctx, int index) {
return buildImageLoader(
_picLinkMap[index], index + 1);
},
),
Row(
children: [
GestureDetector(
child: Container(
width: mySize.width * 0.5,
color: Colors.black38,
),
onTap: () {
print("Tap Left");
},
),
GestureDetector(
child: Container(
width: mySize.width * 0.5,
color: Colors.red.withOpacity(0.5),
),
onTap: () {
print("Tap RIGHT");
},
),
],
),
],
),
);
I only want to scroll about half the height of the screen on tap.
I searched the web but did not find a suitable solution.
ScrollController _scrollViewController = ScrollController();
...
var jumpTo = (MediaQuery.of(context).size.height - 104)/2;
//104 is random number for the rest of the screen widgets (e.g. appbar ..)
_scrollViewController.jumpTo(jumpTo); //pixel value
...
ListView.builder(
controller: _scrollViewController,