This file contains 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
## Flutter iOS & Android | |
State Management: Riverpod | |
- https://riverpod.dev/docs/from_provider/provider_vs_riverpod | |
- https://www.youtube.com/watch?v=BJtQ0dfI-RA&ab_channel=Flutter | |
- https://www.youtube.com/watch?v=UyepBhIY5Bo&ab_channel=HeyFlutter%E2%80%A4com | |
- https://www.youtube.com/watch?v=Zp7VKVhirmw&ab_channel=ResoCoder | |
Language: Dart | |
### Things to Search |
This file contains 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
var mInterstitialAd: InterstitialAd? = null | |
fun loadInterstitial(context: Context) { | |
InterstitialAd.load( | |
context, | |
"ca-app-pub-3940256099942544/1033173712", //Change this with your own AdUnitID! | |
AdRequest.Builder().build(), | |
object : InterstitialAdLoadCallback() { | |
override fun onAdFailedToLoad(adError: LoadAdError) { | |
mInterstitialAd = null |
This file contains 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
@AndroidEntryPoint | |
class MainFragment : Fragment() { | |
private val viewModel: MainViewModel by viewModels() | |
private val tokenViewModel: TokenViewModel by activityViewModels() | |
private lateinit var navController: NavController | |
private var token: String? = null | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, |
This file contains 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
@AndroidEntryPoint | |
class LoginFragment : Fragment() { | |
private val viewModel: AuthViewModel by viewModels() | |
private val tokenViewModel: TokenViewModel by activityViewModels() | |
private lateinit var navController: NavController | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? |
This file contains 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
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "data_store") | |
@Module | |
@InstallIn(SingletonComponent::class) | |
class SingletonModule { | |
@Singleton | |
@Provides | |
fun provideTokenManager(@ApplicationContext context: Context): TokenManager = TokenManager(context) |
This file contains 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
LazyColumn(state = lazyColumnListState) { | |
items( | |
items = articles, | |
key = { it.url }, | |
) { article -> | |
Text( | |
modifier = Modifier | |
.height(75.dp), | |
text = article.title, | |
) |
This file contains 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
@HiltViewModel | |
class NewsManuelPagingViewModel @Inject constructor( | |
private val repository: NewsManuelPagingRepository, | |
): ViewModel() { | |
val newsList = mutableStateListOf<Article>() | |
private var page by mutableStateOf(1) | |
var canPaginate by mutableStateOf(false) | |
var listState by mutableStateOf(ListState.IDLE) |
This file contains 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
@Composable | |
fun PagingListScreen() { | |
val viewModel = hiltViewModel<NewsViewModel>() | |
val articles = viewModel.getBreakingNews().collectAsLazyPagingItems() | |
LazyColumn { | |
items( | |
items = articles, | |
key = { it.url } |
This file contains 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
@Composable | |
fun ExampleScreen( | |
sharedViewModel: SharedViewModel, | |
) { | |
val context = LocalContext.current | |
val listState = rememberLazyListState() | |
val expandedFabState = remember { | |
derivedStateOf { | |
listState.firstVisibleItemIndex == 0 | |
} |
This file contains 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
Column( | |
horizontalAlignment = Alignment.End, | |
verticalArrangement = Arrangement.Center, | |
) { | |
SmallFloatingActionButton( | |
onClick = { sharedViewModel.smallFabOnClick.value.invoke() }, | |
containerColor = colors.secondaryVariant, | |
shape = RoundedCornerShape(12.dp), | |
) { | |
Icon( |
NewerOlder