Skip to content

Instantly share code, notes, and snippets.

@Piinks
Created March 28, 2024 20:52
Show Gist options
  • Save Piinks/c6d105aa77e9b620f10d4e42e1a957d9 to your computer and use it in GitHub Desktop.
Save Piinks/c6d105aa77e9b620f10d4e42e1a957d9 to your computer and use it in GitHub Desktop.
Reverse chat layout
// Copyright 2019 the Dart project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
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',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
final List<String> messages = [
'Hey!',
'What\'s up?',
'Want to grab Dinner?',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Demo'),
),
body: CustomScrollView(
reverse: true,
slivers: [
SliverList.builder(
itemCount: messages.length,
itemBuilder: (_, int i) {
int index = messages.length - (i + 1);
return Text(messages[index]);
},
),
],
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment