Skip to content

Instantly share code, notes, and snippets.

@aqua30
aqua30 / card_stack_animation.dart
Created March 21, 2024 18:57
Card Stacking UI in Flutter with Animation
import 'package:flutter/material.dart';
import 'package:ui_animations/cards/expanded_card.dart';
import 'cards/summary_card.dart';
class CardStackAnimation extends StatefulWidget {
const CardStackAnimation({super.key});
@override
State<StatefulWidget> createState() => _CardStackAnimation();
val userImages = listOf(
R.drawable.img_user_1,
R.drawable.img_user_2,
R.drawable.img_user_3,
R.drawable.img_user_4,
R.drawable.img_user_5,
)
...
/**
* [DashboardFragment] is a custom flutter fragment which is used to pass custom
* data from native app to dashboard part in flutter. This communication is set up on
* both native and in flutter module.
*
* @see To refer to the flutter part, please refer the flutter module.
* */
const val KeyData = "key_data"
const val CommunicationChannel = "com.app/dataShare"
LazyColumn(
modifier = Modifier.padding(horizontal = 16.dp),
horizontalAlignment = Alignment.Start,
) {
item {
Spacer(modifier = Modifier.height(4.dp))
}
items(
items = chatListItems,
key = { chatData ->
HorizontalPager(
pageCount = 3,
beyondBoundsPageCount = 3,
state = viewPagerState,
modifier = Modifier
.background(MaterialTheme.colors.background)
.fillMaxSize(),
) { page ->
when (page) {
0 -> ChatListScreen()
TabRow(
modifier = Modifier.fillMaxWidth(),
selectedTabIndex = selectedPage,
indicator = { tabPositions ->
}
) {
homeTabs.forEachIndexed { index, tabData ->
Tab(
selected = index == selectedPage,
) {
Row(
modifier = Modifier,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = stringResource(id = R.string.whatsapp_title),
style = TextStyle(
fontSize = 22.sp,
fontWeight = FontWeight.SemiBold,
color = if (isSystemInDarkTheme()) PrimaryGray_A101 else White
Box {
Column {
AppBar()
TabBar()
HorizontalPager()
}
FloatingActionButton()
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val viewModel: MainViewModel by viewModels()
var isEligible by remember {
mutableStateOf(false)
}
LaunchedEffect(true) {
class MainViewModel: ViewModel() {
private val _creditScore = MutableStateFlow(0)
private val _age = MutableStateFlow(18)
val isEligible = combine(_creditScore, _age) { creditScore, age ->
creditScore > 400 && age > 18 && age < 70
}
fun creditScore(score: Int) {