Draggable object cannot be moved in DragTarget widget flutter - flutter

I am trying to move/drag drop widget inside DragTarget but don't know what is the issue. Here is my code:
return Scaffold(
drawer: DrawerWidget(),
appBar: AppBar(
backgroundColor: Colors.white,
title: Text(
'Table Layout',
style: Theme.of(context).textTheme.title.merge(
TextStyle(letterSpacing: 1.3),
),
),
centerTitle: true,
elevation: 0,
),
body: Container(
child: Row(
children: [
Container(
color: Colors.blue[100],
width: MediaQuery.of(context).size.width * 0.30,
child: ListView.separated(
padding: const EdgeInsets.all(16.0),
itemCount: 3,
separatorBuilder: (context, index) {
return const SizedBox(
height: 12.0,
);
},
itemBuilder: (context, index) {
return Draggable<String>(
data: images[index],
dragAnchor: DragAnchor.pointer,
feedback: MenuListItem(
photoProvider: images[index],
),
child: MenuListItem(
photoProvider: images[index],
),
);
},
),
),
Expanded(
child: Container(
height: double.infinity,
width: double.infinity,
color: Colors.grey,
child: DragTarget<String>(
builder: (context, candidateItems, rejectedItems) {
return Stack(
children: targetList.map((image) {
return Draggable<String>(
data: image,
dragAnchor: DragAnchor.pointer,
childWhenDragging: Container(),
feedback: MenuListItem(
photoProvider: image,
),
child: MenuListItem(
photoProvider: image,
),
);
}).toList(),
);
},
onWillAccept: (data) {
return true;
},
onAccept: (item) {
},
),
),
),
],
),
),
);
When I run the app the element appears at the top left corner. I am trying to place that widget anywhere inside DragTarget by dragging but after dragging it return to its original place.
Can anyone help me please.
Thanks

Related

how to scroll the screen Listview builder inside column

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 1,
backgroundColor: appBarColor,
centerTitle: true,
title: const Text('News'),
),
body: Column(
children: [
news.length < 2
? ImageSlideshow(
children: [NewsSlideWidget0(news: news)],
)
: ImageSlideshow(
children: [
NewsSlideWidget0(news: news),
NewsSlideWidget1(news: news)
],
),
Container(
color: Colors.white,
child: ListTile(
// selectedTileColor: Colors.white,
title: Text(news_screen_title, style: news_screen_title_tstyle),
subtitle: Text(news_screen_subtitle),
),
),
news.isEmpty
? const CircularProgressIndicator()
: Expanded(
child: LazyLoadScrollView(
onEndOfPage: () => loadNextPage(),
scrollOffset: 10,
child: ListView.builder(
itemCount: news.length,
itemBuilder: (BuildContext context, int i) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewsInnerScreen(
title: news[i].title,
date: news[i].date,
image: news[i].images[0],
content: parse(news[i].content).body!.text,
),
),
);
},
child: Container(
child: ListTile(
contentPadding: EdgeInsets.all(15),
title: Text(
news[i].title,
),
subtitle: Column(
children: [
Text(
parse(news[i].content).body!.text,
style:
),
Text(
news[i].date,
),
],
),
trailing: ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 100,
minHeight: 300,
maxWidth: 104,
maxHeight: 300,
),
child: ClipRRect(
child: Image(
image: NetworkImage(
news[i].images[0],
),
),
),
),
),
),
),
);
},
),
),
),
],
),
);
}
my screen is like this I want this column to scrollable I tried singlechildscrollview and listview those did not work for me and I use a plugin for pagination and I use more widgets also and I extracted that and u I use image slide show packages for carousel so how can I do that I am new to flutter please let me know
All list builder in Flutter have property called "shrinkWrap"
Just turn it to "true"

Strange behavior of Flutter ImageFilter.blur

When I use this, the edges of the container are rendered incorrectly (blurred white edges)
Here is the screenshot
Only the image is blurry (centered), but for some reason a blurry white line is displayed at the very top.
Any help is welcome.
Here is the code
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
toolbarHeight: 0,
elevation: 0,
),
body: SafeArea(
child: StatefulBuilder(builder: (ctx, _setState) {
return ColoredBox(
color: Colors.black,
child: Align(
alignment: Alignment.center,
child: GestureDetector(
onVerticalDragEnd: (details) {
if (details.velocity.pixelsPerSecond.dy < -100 ||
details.velocity.pixelsPerSecond.dy > 100) {
Get.back();
}
},
child: CarouselSlider(
options: CarouselOptions(
viewportFraction: 1,
height: double.infinity,
enableInfiniteScroll: false,
disableCenter: true,
autoPlayCurve: Curves.bounceOut,
initialPage: widget.activeSlide,
onPageChanged: (page, _reason) {
_setState(() => widget.activeSlide = page);
},
scrollPhysics: kDefaultScrollPhysics
),
items: widget.post.images.map((image) {
return Builder(
builder: (BuildContext context) => Stack(
children: [
Center(
child: Image.network(
ApiConfig.ensureUrl(image.original) + image.original,
width: double.infinity,
fit: BoxFit.cover,
),
),
Center(
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
decoration: BoxDecoration(color: Colors.white.withOpacity(0.0)),
),
),
),
),
Center(
child: Image.network(
ApiConfig.ensureUrl(image.original) + image.original,
fit: BoxFit.contain,
),
),
],
),
);
}).toList(),
),
),
));
}),
),
);
I expect the image to blur correctly and the edges of the container to be completely black (like its background)

How to code dynamic FlipCard List with FutureBuilder in Flutter

I am very new at flutter and I tried writing "body: new ListView.builder....." but it does not work, I am getting always red underline. Can you help me to fix this. I am getting the data to the flipcards from json albüm so I think I must use future builder
This is what it looks like, I want multiple cards according to the elements from json:
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Center(
child: Text(
"Main",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22.0),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),
backgroundColor: Colors.green[600],
),
body: Center(
child: FutureBuilder<Album>(
future: futureAlbum,
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView(
children: [
const SizedBox(height: 10),
Container(
margin: const EdgeInsets.all(15.0),
height: 200,
width: 350,
child: FlipCard(
direction: FlipDirection.HORIZONTAL,
front: Container(
....................
),
back: Container(
.......................
),
),
),
],
);
} else if (snapshot.hasError) {
return ListView(
children: [
SizedBox(height: 10),
Container(
margin: const EdgeInsets.all(15.0),
height: 200,
width: 350,
child: FlipCard(
direction: FlipDirection.HORIZONTAL,
front: Container(
back: Container(
),
),
),
],
);
}
},
),
),
),
);
}

I want to get a download URL from firebase Storage

here is my build code for getting the URL from firebase storage and showing the image. The image name is save on my firestore as array. So i need to get the list of the image name and turn it into list of URL from firestorage.
#override
Widget build(BuildContext context){
return Container(
child: Stack(
children: [
FutureBuilder<QuerySnapshot>(
future: ref.get(),
builder: (context, snapshot) {
if(snapshot.hasError){
return Scaffold(
body: Center(
child: Text("Error: ${snapshot.error}"),
),
);
}
if(snapshot.connectionState == ConnectionState.done){
return Scaffold(
appBar: AppBar(title: Text("Home"),
centerTitle: true,
),
body: GridView(gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200,
childAspectRatio: 2/3,
crossAxisSpacing: 15,
mainAxisSpacing: 15),
children: snapshot.data!.docs.map((document){
DateTime dt = (document['endDateTime'] as Timestamp).toDate();
List im = DownloadURL(document['imageURL']);// this are the call method
return Card(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
child:Column(
children: [
Stack(
alignment: Alignment.center,
children: [
Ink.image(
image: NetworkImage(im[0]),
child: InkWell(
onTap: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context)=>DetailScreen(productId: document.id,)));
},
),
height: 170,
fit: BoxFit.cover,
),
],
),
Expanded(
child: Container(
alignment: Alignment.center,
child: Padding(padding: EdgeInsets.all(4).copyWith(bottom: 0),
child: Text("${document['nameP']}",
style: TextStyle(fontSize: 16),
),
),
),
),
// SizedBox(height: 3),
Expanded(
child: Container(
alignment: Alignment.center,
child: Padding(padding: EdgeInsets.all(6).copyWith(bottom: 0),
child: Text("RM ${document['startPrice']}",
style: TextStyle(fontSize: 16),
),
),
),
),
SizedBox(height: 6),
Expanded(child: CountDownText(due: dt,
finishedText: "The Auction has End",
showLabel: true,
daysTextShort: "D ",
hoursTextShort: "H ",
minutesTextShort: "M ",
secondsTextShort: "S ",
style: TextStyle(fontSize: 16,color: Colors.deepPurpleAccent),
),
),
SizedBox(height: 2),
],
),
);
}).toList(),
),
);
}
//loading State
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
),
],
),
);
}
and here is my method for getting the download URL from firebase storage
DownloadURL(List images) async{
List url = [];
for(int i = 0; i<images.length; i++){
url.add(await st.ref('products/${images[i]}').getDownloadURL());
}
return url;
}
it will show error, type 'Future' is not a subtype of type 'List' when run the code.
DownloadURL should return List.
Future<List<String>> DownloadURL(List images) async {
...
}
See Asynchronous programming

Flutter - Container width and height fit parent

I have a Card widget which includes Column with several other Widgets. One of them is Container.
Widget _renderWidget() {
return Column(
children: <Widget>[
Visibility(
visible: _isVisible,
child: Container(
width: 300,
height: 200,
decoration:
BoxDecoration(border: Border.all(color: Colors.grey)),
child: ListView.builder(
itemCount: titles.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
leading: Icon(icons[index]),
title: Text(titles[index]),
),
);
},
)),
),
],
);
}
Here, if I don't specify width and height I get error. But, is there a way to make them to fit parent element?
EDIT
Full code:
return ListView(
children: <Widget>[
Center(
child: Container(
child: Card(
margin: new EdgeInsets.all(20.0),
child: new Container(
margin: EdgeInsets.all(20.0),
width: double.infinity,
child: Column(
children: <Widget>[
FormBuilder(
key: _fbKey,
autovalidate: true,
child: Column(
children: <Widget>[
FormBuilderDropdown(
onChanged: (t) {
setState(() {
text = t.vrsta;
});
},
validators: [FormBuilderValidators.required()],
items: user.map((v) {
return DropdownMenuItem(
value: v,
child: ListTile(
leading: Image.asset(
'assets/img/car.png',
width: 50,
height: 50,
),
title: Text("${v.vrsta}"),
));
}).toList(),
),
],
),
),
Container(child: _renderWidget()),
text.isEmpty
? Container()
: RaisedButton(
child: Text("Submit"),
onPressed: () {
_fbKey.currentState.save();
if (_fbKey.currentState.validate()) {
print(_fbKey.currentState.value.toString());
print(formData.startLocation);
getAutocomplete();
}
},
)
],
),
)),
),
),
],
);
}
Just set the height and width property of your Container to double.infinity
Solution Code:
Widget _renderWidget() {
return Column(
children: <Widget>[
Visibility(
visible: _isVisible,
child: Container(
width: double.infinity,
height: double.infinity,
decoration:
BoxDecoration(border: Border.all(color: Colors.grey)),
child: ListView.builder(
itemCount: titles.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
leading: Icon(icons[index]),
title: Text(titles[index]),
),
);
},
)),
),
],
);
}
You are using ListView inside Column which is why you need to specify height in your Container to prevent errors.
The best way is to use Expanded or Flexible as parent of your ListView
Expanded(
child: ListView.builder(...)
)
Update:
Widget _renderWidget() {
return Column(
children: <Widget>[
Visibility(
visible: _isVisible,
child: Expanded(
child: ListView.builder(
itemCount: titles.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
leading: Icon(icons[index]),
title: Text(titles[index]),
),
);
},
),
),
),
],
);
}