小编Mne*_*oee的帖子

Flutter:http post上传图片

我使用Web服务进行图像处理,它在Postman中运行良好:

邮差截图

现在我想用Dart扑灭http请求:

import 'package:http/http.dart' as http;

static ocr(File image) async {
    var url = '${API_URL}ocr';
    var bytes = image.readAsBytesSync();

    var response = await http.post(
        url,
        headers:{ "Content-Type":"multipart/form-data" } ,
        body: { "lang":"fas" , "image":bytes},
        encoding: Encoding.getByName("utf-8")
    );

    return response.body;

  }
Run Code Online (Sandbox Code Playgroud)

但我不知道如何上传图像文件,在上面的代码中我得到异常:Bad state: Cannot set the body fields of a Request with content-type "multipart/form-data".
我应该如何编写请求体?

image-uploading httprequest dart flutter

20
推荐指数
9
解决办法
2万
查看次数

Android:强制gradle只包含一个版本的库

'com.android.support:support-v4:23.3.0'在使用我的build.gradle但是在探索外部库时,我看到了两个版本的support-v4库(23.3.0和24.0.0).如何找到哪个依赖项使用support-v4:24.0.0库?如何强制gradle只添加版本23.3.0?

外部图书馆图像

这是我在build.gradle中的依赖列表:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.android.support:recyclerview-v7:23.3.0'
    compile 'com.android.support:cardview-v7:23.3.0'
    compile ('com.nightonke:wowoviewpager:1.0.2') {
        exclude group: 'com.android.support', module:'support-v4'
    }
    compile ('com.j256.ormlite:ormlite-android:5.0'){
        exclude group: 'com.android.support', module:'support-v4'
    }
    compile files('libs/picasso-2.5.2.jar')
    compile files('libs/easyandroidanimationslibrary-v0.5.jar')
    compile files('libs/apache-httpcomponents-httpclient.jar')
    compile files('libs/apache-httpcomponents-httpcore.jar')
    compile 'co.ronash.android:pushe-base:1.2.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'
    compile('com.github.ozodrukh:CircularReveal:2.0.1@aar') {
        transitive = true;
    }
    compile files('libs/btsdk.jar')
    compile project(':zxing_barcode') // this project include the same version of support-v4 library
    compile project(':cropper')// this project include the same version of support-v4 …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio support-v4 gradle-dependencies

18
推荐指数
1
解决办法
2万
查看次数

颤动运行错误:您尚未接受许可协议

我正在开发谷歌扑动的 Android和ios应用程序.
当我添加一个新的依赖就像shared_preferencespubspec.yaml,然后再执行flutter run在终端,我得到这个错误:

  • 出了什么问题:配置项目':shared_preferences'时出现问题.
    您尚未接受以下SDK组件的许可协议:[Android SDK Platform 27].

我知道为什么会这样!因为我系统上最新的Android SDK平台是26.它试图下载sdk 27​​然后失败.没问题!我去了位于这里的图书馆缓存文件夹:

C:\用户\应用程序数据\漫游\酒吧\缓存\主持\ pub.dartlang.org\shared_preferences-0.3.1 \机器人

并编辑build.gradle文件并更改compileSdkVersion 27compileSdkVersion 26.有用.
到目前为止,我必须为所有新的依赖项执行此操作,
是否有任何方法,例如为所有依赖项定义全局build.gradle文件?所以不需要buil.gradle单独编辑每个s.

android android-sdk-tools flutter

10
推荐指数
7
解决办法
1万
查看次数

Android:其父级之外的子视图不响应单击事件

为了获得效果,我扩展了子视图,导致子视图在其父视图的一侧出现.我在子视图中有一个按钮,它在缩放之前有效但在缩放后不起作用.出了什么问题?见下图:

外面的按钮不起作用

为了缩放孩子我使用这个代码:

            childView.bringToFront();
            Animation a = new Animation() {
                @Override
                protected void applyTransformation(float t, Transformation trans) {
                    float scale = 1f * ( 1 - t ) + SCALE_UP_FACTOR * t;
                    childView.setScaleX(scale);
                    childView.setScaleY(scale);
                }

                @Override
                public boolean willChangeBounds() {
                    return true;
                }
            };
            a.setDuration(ANIM_DURATION);
            a.setInterpolator(new Interpolator() {
                @Override
                public float getInterpolation(float t) {
                    t -= 1f;
                    return (t * t * t * t * t) + 1f; // (t-1)^5 + 1
                }
            });
            childView.startAnimation(a); 
Run Code Online (Sandbox Code Playgroud)

父母是ViewPager:

     <ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)

android parent-child android-view onclicklistener

8
推荐指数
1
解决办法
904
查看次数

Flutter:毕加索或通用图像加载器等价物

我是 Google flutter sdk 的新手,用于为 Android 和 ios 开发应用程序,
我想加载大图像ListView
我想异步加载图像并使用缓存,在 Android JAVA/Kotlin 中我使用 Picasso,我怎样才能获得类似的行为在颤振中?

官方颤振ListView示例:Flutter 中 ListView 的替代方案是什么

android listview ios picasso flutter

8
推荐指数
1
解决办法
5053
查看次数

在 Gson 反序列化器旁边使用 Room 持久性库中的 @Embedded

我使用 Google Room 持久性库将数据保存在数据库中。在 Room 中有一个注释(@Embedded):

您可以使用 @Embedded 注释来表示您想要分解为其在表中的子字段的对象。然后,您可以像查询其他单独列一样查询嵌入字段

@Entity
public class MyObject {

// nested class
public class GeneralInfo {

    public String ownerName;

    @PrimaryKey
    public long wellId;
}

@Embedded
public GeneralInfo generalInfo;

public long objectId;

// other fields
}
Run Code Online (Sandbox Code Playgroud)

我使用 Gson 从 REST API 反序列化 json 字符串,我希望 Gson 直接将GeneralInfo字段反序列化为MyObject字段。我怎样才能做到这一点?

我希望 GsonMyObject像这样反序列化 s:

{
    objectId : 1
    wellId : 1
    ownerName : "Me"
}
Run Code Online (Sandbox Code Playgroud)

不是这个

{
    generalInfo : {        
        wellId : 1
        ownerName …
Run Code Online (Sandbox Code Playgroud)

java json pojo gson android-room

6
推荐指数
1
解决办法
593
查看次数

Android RecyclerView:拖放多个 ViewType

我为 a 实现了拖放,RecyclerView当有一种View类型时效果很好,RecyclerView但当有多种视图类型时重置,我在这个 gif 中显示结果:
屏幕录像机

这是我的代码:

public class RecyclerListAdapter extends RecyclerView.Adapter<ItemViewHolder> {

    private final Integer[] INVOICE_ITEMS_LIST = new Integer[]{
            INVOICE_DESIGN_TITLE,
            INVOICE_DESIGN_TITLE,
            INVOICE_DESIGN_LOGO,
            INVOICE_DESIGN_TITLE
    };

    public RecyclerListAdapter() {
        mItems.addAll(Arrays.asList(INVOICE_ITEMS_LIST));
    }

    @Override
    public int getItemViewType(int position) {
        return INVOICE_ITEMS_LIST[position];
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        switch (viewType){
            case INVOICE_DESIGN_TITLE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.invoice_design_item_title, parent, false);
                break;
            case INVOICE_DESIGN_LOGO:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.invoice_design_item_logo, parent, false);
                break;
            default:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.invoice_design_item_title, parent, false);
        }


        return …
Run Code Online (Sandbox Code Playgroud)

android drag-and-drop android-view android-recyclerview

5
推荐指数
1
解决办法
2006
查看次数

Android:在Nougat中获取整个WebView的截图(Android 7)

我使用下面的代码从a截取屏幕截图WebView.它在Android 6及更低版本中运行良好,但在Android 7中它只占用webview的可见部分.

// before setContentView
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            WebView.enableSlowWholeDocumentDraw();
        }
...
// before set webview url
webView.setDrawingCacheEnabled(true);
// after html load complete
final Bitmap b = Bitmap.createBitmap(webView.getMeasuredWidth(),
                webView.getContentHeight(), Bitmap.Config.ARGB_8888);
        Canvas bitmapHolder = new Canvas(b);
        webView.draw(bitmapHolder);
Run Code Online (Sandbox Code Playgroud)

但位图b不完整.如何WebView在Android Nougat中截取整个屏幕截图?

编辑:
我发现webView.getContentHeight不行.我对整个webview高度进行了硬编码,效果很好.问题是:如何WebView在Android Nougat中获得整体内容高度?

android screenshot webview android-7.0-nougat

5
推荐指数
1
解决办法
575
查看次数

如何在 Flutter 中检测用户不活动

我使用 Java 开发了 Android 应用程序,现在想迁移到Flutter

为了检测用户不活动,我在 Activity 中重写此方法:onUserInteraction并重置 a Timer,如果没有用户交互,我会显示一个类似动画的屏幕保护程序。

Flutter 有没有干净的方法来做到这一点?我不想使用平台渠道。我想要纯粹的 Dart 和 flutter。我知道我可以设置计时器并在用户触摸时重置它,但就像在 Android 中一样,我希望系统通知我有关用户交互的信息。

android screensaver dart flutter flutter-channel

4
推荐指数
1
解决办法
6689
查看次数

折叠CollapsingToolbarLayout完全崩溃

我在AppBarLayout中使用CollapsingToolbarLayout只是因为它在滚动时的视差效果,所以我需要完全折叠布局.我的意思是在向下滚动后将其高度设置为零.我将布局minHeight设置为0dp但不起作用,并且仍然可以看到部分布局.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="40dp"
        android:paddingRight="40dp"
        android:paddingLeft="40dp"
        android:background="#e91e63"
        android:fitsSystemWindows="true"
        android:minHeight="0dp"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="0dp"
            android:fitsSystemWindows="true"
            app:titleEnabled="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <ImageView
                    android:id="@+id/index_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/suitcase"
                    android:padding="20dp"
                    android:background="@drawable/index_page_icon_bg"
                    android:layout_margin="5dp"
                    app:layout_collapseMode="parallax"/> 

            </LinearLayout>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:minHeight="0dp"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>   
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">
        </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

发生了什么我不想要的

一般规则:如果您认为这不是一个好的Q,请在评论中声明然后做您喜欢的任何事情!

android android-collapsingtoolbarlayout

3
推荐指数
1
解决办法
2326
查看次数

颤动:IconButton onPressed没有被调用

我在ScaffoldappBar中将一个widget列表作为动作,但是当我按下它们时它们没有响应,我floatingButton在场景中也有一个并且它完美地工作.

appBar: new AppBar(
        title: new Text(
            widget.title,
          style: new TextStyle(
            fontFamily: 'vazir'
          ),
        ),
        centerTitle: true,
        actions: <Widget>[
          new IconButton(
            icon: new Icon(Icons.search),
            highlightColor: Colors.pink,
            onPressed: _onSearchButtonPressed(),
          ),
        ],
      ),

void _onSearchButtonPressed() {
    print("search button clicked");
  }
Run Code Online (Sandbox Code Playgroud)

即使我把IconButton放在一个RowColumn小部件中,而不是在其中appBar,它也不再起作用.
答:
感谢siva Kumar,我在调用函数时遇到了错误,我们应该这样调用它:

onPressed: _onSearchButtonPressed, // without parenthesis.
Run Code Online (Sandbox Code Playgroud)

或者这样:

onPressed: (){
    _onSearchButtonPressed();
},
Run Code Online (Sandbox Code Playgroud)

android click ios flutter

2
推荐指数
1
解决办法
5555
查看次数

Flutter Flame:正确的视口以匹配屏幕尺寸

如何找出屏幕尺寸并根据屏幕分辨率放置我的游戏项目?我想在网络客户端上运行我的游戏。

屏幕外的组件

我想调整红色游戏组件的大小,使其适合屏幕并位于中心位置。
LibGdx 对于这个概念有一些很好的 java 类:链接

dart flutter flame

1
推荐指数
1
解决办法
4998
查看次数