My codes:
class MovieDetailView extends StatefulWidget {
const MovieDetailView({super.key});
@override
State<MovieDetailView> createState() => _MovieDetailViewState();
}
List<MovieModel> relatedMovies = [
MovieModel(
id: "1",
title: "Star Wars: The Last agjıjagıwajgwaıg jeaıgjewaıgjwa eıgjewıaogajew",
imageUrl:
"https://tr.web.img3.acsta.net/img/e6/b5/e6b5cdbd386e3255889b6d3a33bb3613.jpg",
year: "2017",
category: "Action, Sci-Fi, Science Fiction",
),
MovieModel(
id: "2",
title: "Star Wars: The Last Jedi",
imageUrl:
"https://tr.web.img3.acsta.net/img/e6/b5/e6b5cdbd386e3255889b6d3a33bb3613.jpg",
year: "2017",
category: "Action, Sci-Fi, Science Fiction",
),
MovieModel(
id: "3",
title: "Star Wars: The Last Jedi",
imageUrl:
"https://tr.web.img3.acsta.net/img/e6/b5/e6b5cdbd386e3255889b6d3a33bb3613.jpg",
year: "2017",
category: "Action, Sci-Fi, Science Fiction",
),
MovieModel(
id: "4",
title: "Star Wars: The Last Jedi",
imageUrl:
"https://tr.web.img3.acsta.net/img/e6/b5/e6b5cdbd386e3255889b6d3a33bb3613.jpg",
year: "2017",
category: "Action, Sci-Fi, Science Fiction",
),
MovieModel(
id: "5",
title: "Star Wars: The Last Jedi",
imageUrl:
"https://tr.web.img3.acsta.net/img/e6/b5/e6b5cdbd386e3255889b6d3a33bb3613.jpg",
year: "2017",
category: "Action, Sci-Fi, Science Fiction",
),
];
class _MovieDetailViewState extends State<MovieDetailView> {
bool _isExpanded = false;
final String _synopsis =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ultricies nisl ac consequat eleifend. Donec euismod mollis blandit. Proin feugiat magna eu nunc malesuada mollis. Duis et lacus non mauris dignissim commodo nec vitae lectus. Sed suscipit dictum neque, non bibendum ligula aliquet et. Ut ultrices at massa nec iaculis.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ultricies nisl ac consequat eleifend. Donec euismod mollis blandit. Proin feugiat magna eu nunc malesuada mollis. Duis et lacus non mauris dignissim commodo nec vitae lectus. Sed suscipit dictum neque, non bibendum ligula aliquet et. Ut ultrices at massa nec iaculis.";
@override
Widget build(BuildContext context) {
return BaseView(
viewModel: MovieDetailViewModel(),
onModelReady: (model) {
model.setContext(context);
},
onPageBuilder: (context, model, child) => Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: BaseBody(
padding: true,
paddingValue: context.horizontalPaddingMedium
.copyWith(top: context.mediumValueH),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// ...
Text("Related Movies", style: context.textTheme.h4),
context.emptySizedHeightBoxLow,
LayoutBuilder(
builder: (context, constraints) {
return Container(
height: context.dynamicHeight(
0.28), // Or any fixed height you prefer
child: ListView.builder(
physics: const BouncingScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: relatedMovies.length,
itemBuilder: (context, index) {
final movie = relatedMovies[index];
return SizedBox(
width: context.dynamicWidth(0.4),
child: Card(
color: Colors.transparent,
margin: EdgeInsets.only(
right: index == relatedMovies.length - 1
? 0
: 10,
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
movie.imageUrl,
height: context.dynamicHeight(0.14),
fit: BoxFit.cover,
),
),
context.emptySizedHeightBoxLow,
Expanded(
child: RichText(
text: TextSpan(
text: movie.title,
style: context.textTheme.h5.copyWith(
color: context.colors.onSurface,
),
children: [
TextSpan(
text: " (${movie.year})",
style: context.textTheme.h6
),
],
),
),
),
],
),
),
);
},
),
);
},
),
],
),
),
),
],
),
),
);
}
}
I want Horizontal ListView.Builder
to get automatic height value. How do I do this? The reason why I want it to have automatic height is that the title
can sometimes be long and this may affect the Card
height.
I reviewed the results in an internet search, but I haven’t found any results yet. Thanks in advance for your help.