I have this SectorWidget that I meant it to be something decoupled.
I will pass to it a list of views (of the same height) but I wouldn't like to specify the height hardcoded inside ListView nor outside. I would like it to occupy the same height of widgets, something like wrap_content in Android. But I tried a lot of ways (like this or this) after search and cannot achieve this. Is there a way to do that in my specific case?
import 'package:flixapp/colors.dart';
import 'package:flutter/material.dart';
class SectorWidget extends StatelessWidget {
final SectorViewModel viewModel;
SectorWidget(this.viewModel);
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width,
child: Material(
color: Colors.transparent,
child: InkWell(
splashColor: kSplashColor,
onTap: () {},
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Text(
viewModel.title,
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black54,
fontSize: 30),
),
),
),
),
),
decoration: BoxDecoration(
color: viewModel.titleBackgroundColor ?? Colors.amber),
),
Container(
color: Colors.red,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: viewModel.data?.length ?? 0,
itemBuilder: (BuildContext context, int index) {
var data = viewModel.data;
if (data.isNotEmpty) return viewModel.data[index];
},
),
)
],
);
}
}
class SectorViewModel {
String title;
Color titleBackgroundColor;
List<Widget> data;
SectorViewModel({this.title, this.titleBackgroundColor, this.data});
}