how can i make user assign look stacked? - flutter

I want each user to be stacked, neat as in the picture how can i make user assign look stacked? i want like this :
enter image description here
my result now :
enter image description here
my code :
Row(
children: List.generate(3, (index) {
return Column(
children: [
ClipRRect(
borderRadius:BorderRadius.circular(8),
child: Image.asset(
'asset/img/profile_photo.png',
width: 40,
height: 40,
),
),
],
);
}),
),

To make widgets stack on top of another, you need to use the Stack widget.
Stack(
children: List.generate(3, (index) {
return Padding(
padding: EdgeInsets.only(left: (index * 0.5) * 40), // distance from the left
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.asset(
'asset/img/profile_photo.png',
width: 40,
height: 40,
),
),
);
}),
),

Of course you need to use Stack to make everything looks stacked, not Row. You can use something like this:
#override
Widget build(BuildContext context) {
const WIDTH = 80.0;
return Scaffold(
body: Center(
child: Stack(
children: List.generate(7, (index) {
return Positioned(
left: (WIDTH - 30) * index,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
border: Border.all(color: Colors.black, width: 1.0*index),
),
width: WIDTH,
height: 40.0,
child: Text(index.toString()),
),
);
})),
),
);
}
Result:
Remember to calculate distance carefully. I use Positioned and calculate left distance = (WIDTH - 30) * index. It is kinda same as your images, just adjust few things, then OK. Good luck!

This is how i usually do stacked widgets like that. try it out
Stack(
clipBehavior: Clip.none,
children: [
for (var i = 0; i < yourList.length; i++)
Container(
//* you can adjust the margin here base on your desired output
margin: EdgeInsets.only(left: 12 * i.toDouble()),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.asset(
'asset/img/profile_photo.png',
width: 40,
height: 40,
),
),
),
]),

Related

Image is not fitted when used in leading of ListTile

The asset image is 200x200px, but when it used in leading of ListTile it's not fitted as axpected.
The rendered image looks this way. How to display it proportioanlly 90x90 as it's defined in Image height and width properties?
Card(
key: ValueKey(favorites[index]),
margin: EdgeInsets.all(20),
child: ListTile(
leading: kNoImage,
title: Text(favorites[index]),
subtitle: Text(favorites[index]),
trailing: IconButton(
icon: Icon(Icons.close),
onPressed: () {
debugPrint('entry deleted');
},
),
),
);
const kNoImage = Image(
image: AssetImage('assets/no-user-image.png'),
height: 90,
width: 90,
fit: BoxFit.cover,
);
Change the value of fit to something like BoxFit.scaleDown or BoxFit.contain to get the desired result. See the BoxFit docs to see what these values mean.
The max height for leading widget for your case is ≈56px.
So, if you want to explicitly want to keep it 90, I'd suggest you to make your own ListTile with Row() and Column() which is pretty easy.
This is what I found in ListTile(),
final Offset baseDensity = visualDensity.baseSizeAdjustment;
if (isOneLine)
return (isDense ? 48.0 : 56.0) + baseDensity.dy;
if (isTwoLine)
return (isDense ? 64.0 : 72.0) + baseDensity.dy;
return (isDense ? 76.0 : 88.0) + baseDensity.dy;
I prefer not to use ListTile because of it default behavior. Therefor, I prefer
on dartPad or on Gist
Custom ListTile
Card(
elevation: 8,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(defaultBorderRadiusCircular),
),
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
SizedBox(
width: 90.0,
height: 90.0,
child: ClipRRect(
borderRadius:
BorderRadius.circular(defaultBorderRadiusCircular),
child: Image.asset(
'imagePath',
width: 90,
height: 90,
fit: BoxFit.cover,
),
),
),
const SizedBox(
width: 24,
),
Column(
children: [
const Text(
'Danau Beretan',
),
const Text(
'Indonesia',
),
],
),
],
),
Row(
children: [
Icon(Icons.star_half_outlined),
Text("4.5"),
],
)
],
),
),
),

How to get Flutter Draggable to work with Agora Video frame

I have this video calling Application I am working on. Everything seems to be falling in place. I have a small issue with one UI effect I am trying to implement.
So here is the situation:
When on a live call, like on messenger or any other video calling application, I want user 0, to be able to drag and place their video frame at different positions in the screen.
I tried this using flutter draggable:
/// Video 0 View Customization to include draggable effect
Offset? position;
double prevScale = 1;
double scale = 1;
void updatePosition(Offset newPosition) =>
setState(() => position = newPosition);
ValueNotifier<Offset?> positionNotifier = ValueNotifier(null);
/// Video layout wrapper
Widget _viewRows() {
final views = _getRenderViews();
switch (views.length) {
case 1:
return Container(
child: Column(
children: <Widget>[_videoView(views[0])],
));
case 2:
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Stack(
children: <Widget>[
_expandedVideoRow([views[1]]),
Positioned(
left: position == null
? MediaQuery.of(context).size.width / 1.5
: position!.dx,
top: position == null ? 50 : position!.dy,
child: Draggable(
maxSimultaneousDrags: 1,
feedback: Transform.scale(
scale: scale,
child: Container(
height: MediaQuery.of(context).size.height / 4.5,
width: MediaQuery.of(context).size.width / 3.2,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(20.0),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: _expandedVideoRow([views[0]]))),
),
childWhenDragging: Opacity(
opacity: .3,
child: Transform.scale(
scale: scale,
child: Container(
height: MediaQuery.of(context).size.height / 4.5,
width: MediaQuery.of(context).size.width / 3.2,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(20.0),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: _expandedVideoRow([views[0]]))),
),
),
onDragEnd: (details) => updatePosition(details.offset),
child: Transform.scale(
scale: scale,
child: Container(
height: MediaQuery.of(context).size.height / 4.5,
width: MediaQuery.of(context).size.width / 3.2,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(20.0),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: _expandedVideoRow([views[0]]))),
),
),
),
],
));
default:
}
return Container();
}
These is then displayed in another main stack: #override
Widget build(BuildContext context) {
Stack(
fit: StackFit.expand,
children: [
if (widget.calltype == 'videocall') ...[
child: _viewRows(),
]
...
Is there any better way to attain this UI Draggable effect?
You can use this widget to make it draggable
https://pub.dev/packages/draggable_widget

Flutter multiple items in Row with Expanded/Flexible

I want to have more(in this example 4) items in Row. I tried use Expanded or Flexible or mainAxisAlignment: MainAxisAlignment.spaceEvenly to fill up all width of screen. But I want to heve items lets say specific width and height 50 pixels, and GestureDetector which is around item to be 1/4 of screen(4 items = full width). So everywhere I tap in the row something will be selected. My problem is that every my solution deforms items(circles) or circle must be very huge to width = height to not be deformed.
I also tried wrapping whole _ratingEmoji in Expanded and giving ratingItem.ratingIndicator constraints to max width but with same result.
Row of items:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
for (var ratingItem in editGroceryRatingProvider.foodRatings)
_ratingEmoji(editGroceryRatingProvider, ratingItem, context),
],
),
Item:
Widget _ratingEmoji(EditGroceryRatingProvider editGroceryRatingProvider,
SelectedFoodRating ratingItem, BuildContext context) {
return GestureDetector(
child: ratingItem.selected
? Container(
width: MediaQuery.of(context).size.width / 8,
height: MediaQuery.of(context).size.width / 8,
padding: const EdgeInsets.all(2.0),
decoration: BoxDecoration(
border: Border.all(
color: Color(0xFF312ADB),
width: 3.0,
),
borderRadius: BorderRadius.circular(32.0)),
child: Center(
child: ratingItem.ratingIndicator,
),
)
: ratingItem.ratingIndicator,
onTap: () => editGroceryRatingProvider.updateSelectedRating(ratingItem),
);
}
RatingIndicator which is "circle" item to be on the screen:
Container(
decoration: BoxDecoration(
border: Border.all(
color: color,
width: 1.5,
),
borderRadius: BorderRadius.circular(64.0),
),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.white,
width: 3.0,
),
borderRadius: BorderRadius.circular(64.0),
),
child: ClipOval(
child: Container(
width: width ?? MediaQuery.of(context).size.width / 7,
height: height ?? MediaQuery.of(context).size.width / 7,
color: color,
),
),
),
);
Thanks a lot.
Update:
Items should stay as they are on screenshot, but "whole" row should be clickable(means even if you click between 2 items, one closer to click should be selected)
Check, please solution.
The whole area is clickable. You just need to add your item instead of mine.
#override
Widget build(BuildContext context) {
final colors = [Colors.red, Colors.blue, Colors.brown, Colors.cyan];
return Scaffold(
body: Container(
alignment: Alignment.center,
color: const Color(0xffFAFAFA),
child: Row(
children: List.generate(
colors.length,
(index) => Expanded(
child: GestureDetector(
onTap: () => print('Tapped:$index'),
child: Container(
height: 50,
color: Colors.transparent,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: colors[index],
),
),
)),
)),
),
),
);

How to design a flutter timeline widget with fixed times and variable events

I'm making a vertical timeline in flutter but I've hit a roadblock on how to design the timeline and event system. The image below is what I have and how I want it to show. The yellow container is the event, events can be on either side and overlap other events. Currently it's three rows inside a column, with the sides expanded and middle fixed width. Each dot is its own widget with a datetime associated with it.
Now my issue is, how can I make it so that the events line up with the center numbers based on datetime?
I'm currently using positioned on the event with top, but I have no way of getting the distance from the top of the center widgets.
main build
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildLeftCol(),
_buildCenterCol(CustomTime().times),
_buildRightCol(12)
],
),
)
],
),
_buildLeftCol
Widget _buildLeftCol() {
return Expanded(
child: Container(
child: Stack(
children: <Widget>[
_buildEventItem(DateTime.now()),
],
)
),
);
}
_buildEventItem
Widget _buildEventItem(DateTime time) {
var index = CustomTime().getIndexOf(time);
var position = 41.0 * index;
return Positioned(
left: 160,
top: position,
child: Container(
width: 200,
height: 200,
color: Colors.yellow,
child: Text("data")
),
);
}
Widget _buildCenterCol(List<DateTime> list) {
return Column(children: list.map((time) => timeItem(time)).toList());
}
Widget timeItem(DateTime time) {
if(time.minute != 00) {
return Padding(
padding: const EdgeInsets.only(top:8.0, bottom: 8.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(9.0),
child: Container(
height: 18,
width: 18,
color: Color(0xFF0288D1),
),
),
);
} else {
return ClipRRect(
borderRadius: BorderRadius.circular(32.0),
child: Container(
height: 64,
width: 64,
color: Color(0xFF00305A),
child: Center(child: Text(DateFormat('HH').format(time), style: TextStyle(color: Colors.white, fontSize: 32.0),))
)
);
}
}
You can try the timeline_tile package released recently. Currently it does not provide dotted lines, but you can easily achieve what you desire with its tiles, for example:
TimelineTile(
alignment: TimelineAlign.center,
rightChild: Container(
constraints: const BoxConstraints(
minHeight: 120,
),
color: Colors.lightGreenAccent,
),
leftChild: Container(
color: Colors.amberAccent,
),
);
If aligned center os manual you can have children on both sides.
Also, the beautiful_timelines repository contains some examples built with this package.

How to put view above the list view?

I have a listview which is equally divided into two parts(act as a background) How can i put a view above it( 100*100 w*h )?(This box should center align & top of root)
here is my tried code -
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
Container(
width: ((context.findRenderObject() as RenderBox).size.width),
height: ((context.findRenderObject() as RenderBox).size.height)/2,
color: darkGreen,
),
// SizedBox(width: 10,),
Container(
width: ((context.findRenderObject() as RenderBox).size.width),
height: ((context.findRenderObject() as RenderBox).size.height)/2,
color: Colors.grey,
),
],
),
);
}
}
First of all, you don't need this line:
((context.findRenderObject() as RenderBox).size.width)
you can replace it with:
double.infinity
and it will take the maximum width the parent Widget can allow.
as for your question, you can wrap your ListView in a Stack:
Container(
width: double.infinity,
height: double.infinity,
child: Stack(
children: <Widget>[
ListView(
children: <Widget>[
Container(
width: double.infinity,
height:
((context.findRenderObject() as RenderBox).size.height) / 2,
color: darkGreen,
),
// SizedBox(width: 10,),
Container(
width: double.infinity,
height:
((context.findRenderObject() as RenderBox).size.height) / 2,
color: Colors.grey,
),
],
),
//place your desired widget here
],
),
),