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()
}
@aqua30
aqua30 / AdjustingViewPager.kt
Created May 1, 2021 09:29
Adjusting View Pager which adjusts its height according to the view's height in focus
package com.aqua30.learningproject
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.View
import android.view.View.MeasureSpec
import androidx.viewpager.widget.ViewPager
class AdjustingViewPager: ViewPager {
private lateinit var repository: UserRepository
private lateinit var testApis: TestApis
private lateinit var mockWebServer: MockWebServer
@Before
fun setUp() {
mockWebServer = MockWebServer()
mockWebServer.start()
testApis = RetrofitHelper.testApiInstance(mockWebServer.url("/").toString())
repository = UserRepositoryImpl(testApis)