Skip to content

Instantly share code, notes, and snippets.

@lvsecoto
lvsecoto / AnimatedSizeAndFade.dart
Created May 29, 2024 02:30
组件大小/内容变化动画
import 'package:flutter/material.dart';
class AnimatedSizeAndFade extends StatelessWidget {
/// 每当Child内容发送改变,就会产生动画
///
/// * 大小发送改变,会有边界变换效果
/// * 内容变化,会有淡出淡入效果(和大小变化不一样,内容变化是通过[child]的类型或者key识别)
/// * 可以指定变化时,组件对齐的位置,比如一个上下展开收起效果的组件,那么它的[alignment]应该传[Alignment.topCenter]
const AnimatedSizeAndFade({
super.key,
/// 这里通过mixin给ProviderNotifier添加一些常用操作
// ignore_for_file: invalid_use_of_internal_member
library provider.notiifer;
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:riverpod/riverpod.dart';
@lvsecoto
lvsecoto / AnimatedVisibilityWidget.dart
Created May 29, 2024 02:30
动画显示/隐藏组件
import 'package:flutter/material.dart';
Widget _defaultAnimationWidgetBuilder(
BuildContext context,
Animation<double> animation,
Widget? child,
) {
return SizeTransition(
axis: Axis.horizontal,
sizeFactor: animation,
/// 对象状态[T]的历史堆栈,可以推入或者弹出
class HistoryStack<T> {
/// 最大索引的数据,即为最新的状态
final _store = <T>[];
/// 读取内容,用于保存的数据
({
List<T> store,
int step,
# 修改应用图标
# 1. 添加依赖
# flutter pub add dev:flutter_launcher_icons
# 2. 运行
# flutter pub run flutter_launcher_icons
flutter_launcher_icons:
android: "launcher_icon"
ios: true
macos:
generate: true
import Foundation
func hexCharAsNumber(_ char: String) -> Int64 {
assert(char.count == 1)
let c = Int64((char as NSString).character(at: 0))
if c >= Int(("a" as NSString).character(at: 0)) {
return c - 87
} else {
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class TKCalculateUtils {
public static long hexCharAsNumber(char c) {
if (c >= 'a') {
return c - 87;
} else {
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.View;
private static LifecycleOwner mockLifecycleOwner() {
LifecycleOwner owner = mock(LifecycleOwner.class);
LifecycleRegistry lifecycle = new LifecycleRegistry(owner);
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
when(owner.getLifecycle()).thenReturn(lifecycle);
return owner;
}
@lvsecoto
lvsecoto / ActionLiveData
Created February 12, 2019 02:11
用于接收View的一个参数,就更新ViewModel的LiveData的情况
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.Transformations;
/**
* 每当输入一个参数{@link #input(Object)},就回调{@link OnGetLiveData},生成一个LiveData
*/
public class ActionLiveData<InputType, ResultType> {
private MutableLiveData<InputType> mInput = new EventMutableLiveData<>();