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

拍照获取图片

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