Issue
I want to make a widget (showing tags in a row) that could, and realistically would, be too long for the width of the screen and that you could swipe left or right to see the whole content, I can't seem to find a base widget to rely one. What would be an appropriate way to do this ?
Solution
Well, you can achieve what you need with a horizontal list view. You can also check cookbook for a live demo
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
const title = 'Horizontal List';
return MaterialApp(
title: title,
home: Scaffold(
appBar: AppBar(
title: const Text(title),
),
body: Container(
margin: const EdgeInsets.symmetric(vertical: 20.0),
height: 200.0,
child: ListView(
// This next line does the trick.
scrollDirection: Axis.horizontal,
children: <Widget>[
const Text('Lorem'),
Container(
width: 8,
color: Colors.red,
),
const Text('ipsum dolor sit amet,'),
Container(
width: 8,
color: Colors.red,
),
const Text('consectetur adipiscing elit.'),
Container(
width: 8,
color: Colors.red,
),
const Text(
'Duis porta efficitur nulla ac bibendum. Vivamus vestibulum mi quis dui sollicitudin ultricies. Sed dignissim dignissim ipsum ac sollicitudin.'),
],
),
),
),
);
}
}
Answered By - salihgueler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.