提交 65efd517 authored 作者: yueweilu's avatar yueweilu

拍照获取图片

上级 f1469b77
......@@ -32,7 +32,18 @@ class _CoursePageState extends State<CoursePage> {
icon: Image.asset(
'assets/images/read_history.png',
),
onPressed: () => context.pushNamed(Routes.studyHistory),
onPressed: () async {
// context.pushNamed(Routes.studyHistory);
final canPrint = await CustomDialog.show<bool>(
context: context,
builder: (context) => const Text('是否开始打印?'),
cancel: const Text('取消'),
confirm: const Text('打印'),
onCancel: Navigator.of(context).pop,
onConfirm: () => Navigator.of(context).pop(true),
);
print('------------canPrint-----------------------$canPrint');
},
),
GestureDetector(
onTap: () async{
......
......@@ -30,16 +30,19 @@ class BuildBanner extends StatelessWidget {
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.w),
color: Color.fromRGBO(
random.nextInt(256), // Red
random.nextInt(256), // Green
random.nextInt(256), // Blue
1.0, // Alpha (opacity)
),
// color: Color.fromRGBO(
// random.nextInt(256), // Red
// random.nextInt(256), // Green
// random.nextInt(256), // Blue
// 1.0, // Alpha (opacity)
// ),
),
child: Image.network(item.pic??''),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.w),
child: Image.network(item.pic??'',)
),
// child: CustomImage.asset(
// url: 'assets/images/banner.png',
// width: 130.w,
......
......@@ -76,14 +76,15 @@ class _LibraryPageState extends State<LibraryPage> {
child: Expanded(
child: CustomPullScrollView(
controller: controller.refreshController,
// onRefresh: controller.onRefresh,
onRefresh: controller.onRefresh,
onLoading: controller.onLoading,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
controller.ads.isNotEmpty?Container(
color: Colors.cyan,
color: Colors.transparent,
padding: EdgeInsets.symmetric(horizontal: 10.w),
child: BuildBanner(items:controller.ads)
):const SizedBox(),
......@@ -136,7 +137,7 @@ class _LibraryPageState extends State<LibraryPage> {
Widget _buildCategory(){
return Container(
height: 38,
height: 38.w,
child: GetBuilder<LibraryController>(
init: LibraryController(),
builder: (controller) =>ListView.builder(
......
......@@ -39,7 +39,7 @@ class LibraryCell extends StatelessWidget {
Container(
width: 100.w,
height: 120.w,
color: Colors.red,
color: Colors.white,
),
/// 右侧
Expanded(
......
......@@ -49,9 +49,6 @@ class _UserInfoPageState extends State<UserInfoPage> {
onTap: () async {
final assets = await AssetsPicker.image(
context: context,
source: ImageSource.gallery,
maxWidth: 512.w,
maxHeight: 512.w,
);
controller.upload(path: assets!.path);
},
......
......@@ -16,6 +16,12 @@ abstract class Access {
return false;
}
/// 相机权限
static Future<bool> camera() async {
final result = await [Permission.camera].request();
return result[Permission.camera] == PermissionStatus.granted;
}
/// 打开设置
static Future<void> setting() async => await openAppSettings();
......
......@@ -3,6 +3,7 @@ part of utils;
abstract class AssetsPicker {
static final ImagePicker _imagePicker = ImagePicker();
/// 获取图库
static Future<XFile?> image({
required BuildContext context,
ImageSource source = ImageSource.gallery,
......@@ -24,4 +25,27 @@ abstract class AssetsPicker {
maxHeight: maxHeight,
);
}
/// 拍照
static Future<XFile?> camera({
required BuildContext context,
ImageSource source = ImageSource.camera,
double maxWidth = 512,
double maxHeight = 512,
}) async {
if (!(await Access.photos())) {
if (context.mounted) {
CustomDialog.showAccess(
context: context,
content: const Text('Requires access to your photo gallery'),
);
}
return null;
}
return _imagePicker.pickImage(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
);
}
}
......@@ -34,7 +34,7 @@ class CustomCard extends StatelessWidget {
width: width,
child: Container(
padding: const EdgeInsets.all(1),
child: CustomImage.network(url: url),
child: CustomImage.network(url: url,placeholder: Image.asset('assets/images/book_placeholder.png'),),
),
);
}
......
......@@ -82,6 +82,9 @@ class CustomDialog extends StatelessWidget {
));
}
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.w), // 调整这里的数值以设置圆角大小
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论