Skip to content

Instantly share code, notes, and snippets.

@SuperPenguin
Created July 9, 2022 11:47
Show Gist options
  • Save SuperPenguin/ad11f7f7d5388d91e0f37b87301c9308 to your computer and use it in GitHub Desktop.
Save SuperPenguin/ad11f7f7d5388d91e0f37b87301c9308 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const App());
}
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
themeMode: ThemeMode.system,
theme: ThemeData(brightness: Brightness.light),
darkTheme: ThemeData(brightness: Brightness.dark),
home: const Home(),
);
}
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('PenguinApp'),
),
body: ListView.builder(
itemCount: 100,
itemBuilder: (context, index) {
return Post(
title: const Text('My Post Title'),
content: const Text(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
),
isFirst: index == 0,
isLast: index == 99,
);
},
),
);
}
}
class Post extends StatelessWidget {
const Post({
Key? key,
this.padding = const EdgeInsets.all(8.0),
required this.title,
required this.content,
this.isFirst = false,
this.isLast = false,
}) : super(key: key);
final bool isFirst;
final EdgeInsets padding;
final Widget title;
final Widget content;
final bool isLast;
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(width: padding.left),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 1.0,
height: padding.top,
child: ColoredBox(
color: !isFirst ? Colors.grey : Colors.transparent,
),
),
const CircleAvatar(),
Expanded(
child: SizedBox(
width: 1.0,
child: ColoredBox(
color: !isLast ? Colors.grey : Colors.transparent,
),
),
),
],
),
const SizedBox(width: 8.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(height: padding.top),
DefaultTextStyle.merge(
style: Theme.of(context).textTheme.titleLarge,
child: title,
),
DefaultTextStyle.merge(
style: Theme.of(context).textTheme.bodyMedium,
child: content,
),
SizedBox(height: padding.bottom),
],
),
),
SizedBox(width: padding.right),
],
),
),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment