盒子上的资产图像

问题描述

我尝试使用 ClipRRect 和 Assetimage 在圆角框上资产图像,

Widget drawingSelection(String indexedImage) {
  Widget result = Align(
    alignment: Alignment(0.0,0.0),child: SizedBox(
      width: 300.0,height: 175.0,child: ClipRRect(
        borderRadius: BorderRadius.circular(36.0),child: Container(
          child: Image(image: Assetimage(indexedImage),),decoration: Boxdecoration(
            color: Colors.white,);
  return result;
}

它说无法资产我的形象,当然我检查了 pub.yaml 并且看起来没问题。 . (仅供参考,indexedImage = aa.jpg) . . 任何人都可以帮助我圆框上的资产图片

解决方法

我看到你通过了 indexedImage = aa.jpg

路径是否指向该图像?因为一个典型的路径是这样的

CREATE OR ALTER PROCEDURE spNewCollectible(@game_id INT,@name VARCHAR(50)) AS
BEGIN
    BEGIN TRANSACTION
        BEGIN TRY
            SELECT * FROM Collectible JOIN Collectible_instance ON Collectible_instance.collectible_id = Collectible.collectible_id WHERE Collectible.game_id = @game_id
            IF @@ROWCOUNT > 0
                THROW 51010,'Nelze přidat předměty po zahájení distribuce předmětů',1; 
            ELSE BEGIN
                IF(SELECT COUNT(collectible_id)FROM Game JOIN Collectible ON Collectible.game_id = Game.game_id WHERE Game.game_id = @game_id GROUP BY Game.game_id)>=10
                    THROW 51011,'Byl dosažen maximální počet předmětů',1; 
                ELSE
                    INSERT INTO Collectible (game_id,collectible_name)VALUES (@game_id,@name)
            END
            COMMIT;
        END TRY
        BEGIN CATCH
            ROLLBACK;
            THROW;
        END CATCH   
END

如果还是不行?可以附上你的 pubspec.yaml 文件吗?

,

因此,您应该遵循两个步骤: 在文件夹中添加图像(在我的情况下,我有资产文件夹), 然后在 pub spec.yaml 中定义 assets 文件夹。 Pubspec File and the Folder image adding in the project

我在这里所做的只是提到了文件夹名称,而不是其中的所有图像。

并查看可以以圆形方式制作图像的多种方法。 只是一个例子,以便它可以帮助其他人。

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
 
  Widget drawingSelection(String indexedImage) {
    Widget result = Align(
      alignment: Alignment(0.0,0.0),child: SizedBox(
        width: 300.0,height: 175.0,child: ClipRRect(
          borderRadius: BorderRadius.circular(36.0),child: Container(
            child: Image(
              image: AssetImage(indexedImage),),decoration: BoxDecoration(
              color: Colors.white,);
    return result;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Users List "),body: SingleChildScrollView(
          child: Column(
            children: [
              drawingSelection("Assets/sample.jpg"),Text("Above is your widget"),SizedBox(
                height: 10,Text("Check out the multiple ways below"),SizedBox(
                height: 20,Text("This is using the container decoration"),Container(
                width: 200.0,height: 200.0,decoration: new BoxDecoration(
                  shape: BoxShape.circle,image: new DecorationImage(
                    fit: BoxFit.fill,image: AssetImage("Assets/sample.jpg"),Text("This is using the ClipOval"),ClipOval(
                child: Container(
                  width: 200,height: 200,child: Image.asset(
                    'Assets/sample.jpg',fit: BoxFit.cover,Text("This is using the ClipRRect"),Container(
                width: 200,child: ClipRRect(
                  borderRadius: BorderRadius.circular(100),Text("This is using the CircleAvatar"),CircleAvatar(
                radius: 100.0,backgroundImage: AssetImage("Assets/sample.jpg"),],);
  }
}

检查一下,让我知道它是否有效。