init
This commit is contained in:
52
lib/widgets/custom_avatar.dart
Normal file
52
lib/widgets/custom_avatar.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class CustomAvatar extends StatelessWidget {
|
||||
String? avtarUrl;
|
||||
double size;
|
||||
double radius;
|
||||
|
||||
CustomAvatar(
|
||||
this.avtarUrl, {
|
||||
Key? key,
|
||||
this.size = 44,
|
||||
this.radius = 4,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (avtarUrl == null || avtarUrl == '') {
|
||||
avtarUrl = 'assets/chats/default_avatar.png';
|
||||
}
|
||||
|
||||
avtarUrl = avtarUrl!.trim();
|
||||
|
||||
return SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
child: _image(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _image() {
|
||||
if (avtarUrl!.contains('http') || avtarUrl!.contains('https')) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: avtarUrl!,
|
||||
width: size,
|
||||
height: size,
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
} else {
|
||||
return Image.asset(
|
||||
avtarUrl!,
|
||||
width: size,
|
||||
height: size,
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
62
lib/widgets/custom_circle_avatar.dart
Normal file
62
lib/widgets/custom_circle_avatar.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class CustomCircleAvatar extends StatelessWidget {
|
||||
String? avtarUrl;
|
||||
double size;
|
||||
Color borderColor;
|
||||
double borderWidth;
|
||||
|
||||
CustomCircleAvatar(
|
||||
this.avtarUrl, {
|
||||
Key? key,
|
||||
this.size = 44,
|
||||
this.borderColor = AppColors.transparent,
|
||||
this.borderWidth = 2,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (avtarUrl == null || avtarUrl == '') {
|
||||
avtarUrl = 'assets/chats/default_avatar.png';
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: size,
|
||||
height: size,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(size / 2),
|
||||
border: Border.all(
|
||||
color: borderColor,
|
||||
width: borderWidth,
|
||||
),
|
||||
),
|
||||
child: PhysicalModel(
|
||||
color: borderColor.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: _image(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _image() {
|
||||
if (avtarUrl!.contains('http')) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: avtarUrl!,
|
||||
width: size,
|
||||
height: size,
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
} else {
|
||||
return Image.asset(
|
||||
avtarUrl!,
|
||||
width: size,
|
||||
height: size,
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
89
lib/widgets/custom_easy_refresh.dart
Normal file
89
lib/widgets/custom_easy_refresh.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
|
||||
class CustomEasyRefresh {
|
||||
static Header get header => ClassicalHeader(
|
||||
refreshText: '下拉刷新',
|
||||
refreshReadyText: '松开刷新',
|
||||
refreshingText: '刷新中...',
|
||||
refreshedText: '刷新完成',
|
||||
infoText: '上次更新 %T',
|
||||
infoColor: AppColors.primary,
|
||||
textColor: AppColors.primary,
|
||||
);
|
||||
|
||||
static Footer get ballFooter => BallPulseFooter(
|
||||
color: AppColors.primary,
|
||||
);
|
||||
|
||||
static Footer get footer => ClassicalFooter(
|
||||
loadText: '上拉加载',
|
||||
loadReadyText: '松开加载',
|
||||
loadingText: '加载中...',
|
||||
loadedText: '加载完成',
|
||||
infoText: '上次更新 %T',
|
||||
noMoreText: '没有更多了',
|
||||
infoColor: AppColors.primary,
|
||||
textColor: AppColors.primary,
|
||||
);
|
||||
|
||||
/// 数据为空的时候显示
|
||||
static Widget empty({
|
||||
String text = '暂无数据',
|
||||
double size = 156.0,
|
||||
}) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/images/empty.png',
|
||||
width: size,
|
||||
),
|
||||
Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.unactive,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static Widget get first => Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
blurStyle: BlurStyle.outer,
|
||||
color: AppColors.shadow,
|
||||
blurRadius: 4,
|
||||
),
|
||||
],
|
||||
),
|
||||
width: 120,
|
||||
height: 120,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: const <Widget>[
|
||||
SpinKitFadingCircle(
|
||||
color: AppColors.primary,
|
||||
size: 50.0,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text('加载中...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
61
lib/widgets/custom_primary_button.dart
Normal file
61
lib/widgets/custom_primary_button.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'package:chat/configs/app_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CustomPrimaryButton extends StatelessWidget {
|
||||
final VoidCallback? onPressed;
|
||||
final String text;
|
||||
final double padding;
|
||||
|
||||
const CustomPrimaryButton({
|
||||
Key? key,
|
||||
required this.text,
|
||||
this.onPressed,
|
||||
this.padding = 0,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.resolveWith(
|
||||
(states) {
|
||||
return EdgeInsets.all(padding);
|
||||
},
|
||||
),
|
||||
shape: MaterialStateProperty.all(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(32),
|
||||
),
|
||||
),
|
||||
backgroundColor: MaterialStateProperty.resolveWith(
|
||||
(states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return AppColors.primary.withAlpha(128);
|
||||
} else {
|
||||
return AppColors.primary;
|
||||
}
|
||||
},
|
||||
),
|
||||
foregroundColor: MaterialStateProperty.resolveWith(
|
||||
(states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return AppColors.white;
|
||||
} else {
|
||||
return AppColors.white;
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user