颤振,如何将图像网络设置为壁纸2021

Posted

技术标签:

【中文标题】颤振,如何将图像网络设置为壁纸2021【英文标题】:flutter , how to set image network as wallpaper 2021 【发布时间】:2021-04-22 00:01:04 【问题描述】:

我正在开发一个设置壁纸的应用程序,它通过链接“imgUrl”进入应用程序,但是当我想将特定图像设置为壁纸它给了我这个错误,

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method requestPermissions on channel flutter.baseflow.com/permissions/methods)

我希望你能给我一个简单的方法来将图像设置为壁纸,以及将图像保存在设备中的方法, 注意:我正在为 Android 使用颤振


import 'package:flutter/material.dart';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:get/get.dart';
import 'package:image_downloader/image_downloader.dart';
import 'package:flutter/services.dart';
import 'dart:async';
import 'dart:io';
import 'dart:async';
import 'dart:typed_data';
import 'package:dio/dio.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:wallpaper/wallpaper.dart';

class ImgDetails extends StatefulWidget 
  @override
  _ImgDetailsState createState() => _ImgDetailsState();


class _ImgDetailsState extends State<ImgDetails> 
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
 
  var imgPath  ;

  String home = "Home Screen",
      lock = "Lock Screen",
      both = "Both Screen",
      system = "System";
 
  String _title = Get.arguments['title'];
  String _imgUrl = Get.arguments['url'];
  @override
  Widget build(BuildContext context) 

    final snackBar = SnackBar(
      content: Text(_title),
      duration: const Duration(seconds:3),
    );
    return Scaffold(
      appBar: AppBar(
       title: Text(_title),
      centerTitle: true,   
      ),
      key: _scaffoldKey,
      body: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Container(
            height: double.infinity,
            child: InteractiveViewer(
              maxScale: 6,
              child: FadeInImage(
                image: NetworkImage(_imgUrl),
                placeholder: AssetImage('assets/img/img_ot_found.jpg'),
              ),
            ),
          ),

          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Container(
              width: MediaQuery.of(context).size.width*0.8,
              height: MediaQuery.of(context).size.height*0.08,
              decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(50),
              gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: [Colors.purple , Colors.purpleAccent]
              )
          ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  IconButton(icon: Icon(Icons.save_alt_rounded , color: Colors.white,size: 32), onPressed: ()
                  ),
                  IconButton(icon: Icon(Icons.imagesearch_roller, color: Colors.white,size: 32), onPressed: ()
                  
                    _modal();
                  ),
                  IconButton(icon: Icon(Icons.info_outline, color: Colors.white,size: 32,), onPressed: ()

                    _scaffoldKey.currentState.showSnackBar(snackBar);
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  

  _askPermission() async 
    if (Platform.isandroid) 
    
      await PermissionHandler().requestPermissions([
        PermissionGroup.storage,
        PermissionGroup.camera,
        PermissionGroup.location,
      ]);
     else 
      await PermissionHandler()
          .checkPermissionStatus(PermissionGroup.storage);
    
  

  _modal() 
    showModalBottomSheet(

        backgroundColor: Colors.white.withOpacity(0.2),
        elevation: 0,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(30,)),
        context: context,
        builder: (BuildContext context) 
          return Container(
            height: 130,
            decoration: BoxDecoration(
                color: Colors.black.withOpacity(0.8),
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(30),
                  topRight: Radius.circular(30),
                )
            ),

            child: Column(

              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                _createTile(context, 'Home Screen', Icons.home, _action1),
                SizedBox(height: 10,),
                _createTile(context, 'Lock Screen', Icons.lock, _action2),
              ],
            ),
          );
        
    );
  

  ListTile _createTile(BuildContext context, String name, IconData icon,
      Function action) 
    return ListTile(
      leading: Icon(icon,
        color: Colors.blueAccent,),
      title: Text(name,
        style: TextStyle(
            color: Colors.white, fontWeight: FontWeight.w500, fontSize: 20),),
      onTap: () 
        Navigator.pop(context);
        action();
      ,
    );
  

  _action1() async 
    if (Platform.isAndroid) 
      await _askPermission();
    
    var response = await Dio()
        .get(_imgUrl, options: Options(responseType: ResponseType.bytes));
    //await ImageGallerySaver.saveImage(Uint8List.fromList(response.data));
    home = await Wallpaper.homeScreen(_imgUrl);
    final result = home = home;
    print(result);
  

  _action2() async 
    if (Platform.isAndroid) 
      await _askPermission();
    
    var response = await Dio()
        .get(_imgUrl, options: Options(responseType: ResponseType.bytes));
    //await ImageGallerySaver.saveImage(Uint8List.fromList(response.data));
    home = await Wallpaper.lockScreen(_imgUrl);
    final result = home = lock;
    print(result);
  
     


【问题讨论】:

【参考方案1】:

您的权限有问题。您需要在 AndroidManifest 文件中添加权限代码。你能把所有的错误日志发给我,让我弄清楚缺少什么权限吗?

【讨论】:

以上是关于颤振,如何将图像网络设置为壁纸2021的主要内容,如果未能解决你的问题,请参考以下文章

如何在android中永久设置壁纸

如何在离子应用程序中将图像设置为墙纸?

如何更改颤振网络应用程序上的图标[重复]

仅设置 Android 主屏幕壁纸

如何将壁纸设置为锁屏或两者(家庭和锁定)?

如何将相机预览设置为壁纸?