Skip to content

Instantly share code, notes, and snippets.

@iampato
Created February 22, 2023 20:01
Show Gist options
  • Save iampato/6796646125bf865e590d91de029cc7d8 to your computer and use it in GitHub Desktop.
Save iampato/6796646125bf865e590d91de029cc7d8 to your computer and use it in GitHub Desktop.
Limited box constraints
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// random strings
final List<String> _items = [
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. aboris nisi ut aliquip ex ea commodo consequ',
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat eprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
const FlutterLogo(),
const SizedBox(height: 50),
LimitedBox(
maxHeight: 100,
maxWidth: double.infinity,
child: PageView.builder(
itemCount: _items.length,
itemBuilder: (context, index) {
return Container(
padding: const EdgeInsets.all(20),
color: Color.fromRGBO(76, 175 + (index * 100), 80, 1),
child: Center(
child: Text(
_items[index],
maxLines: index == 0 ? 1 : 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: Colors.white,
),
)),
);
},
),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment