Created
March 28, 2024 20:52
-
-
Save Piinks/c6d105aa77e9b620f10d4e42e1a957d9 to your computer and use it in GitHub Desktop.
Reverse chat layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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