小编Sam*_*man的帖子

在自定义小部件颤动中使Function参数为可选

我尝试在构造函数中使用一些参数创建一些自定义小部件。该小部件具有一些可选的和必需的参数。如何使Function类型参数在我的可选Widget

class TextInputWithIcon extends StatefulWidget {
  final String iconPath;
  final String placeHolder;
  final Function(bool) onFocusChange;
  const TextInputWithIcon(
      {Key key,
      @required this.iconPath,
      this.placeHolder = "",
      this.onFocusChange})
      : super(key: key);

  @override
  _TextInputWithIconState createState() => _TextInputWithIconState();
}

class _TextInputWithIconState extends State<TextInputWithIcon> {
@override
  Widget build(BuildContext context) {
    return MY_WIDGET;
   }
}
Run Code Online (Sandbox Code Playgroud)

dart flutter

8
推荐指数
3
解决办法
4812
查看次数

在android studio中删除Reformat Code中未使用的导入

我知道Ctrl+Shift+O删除未使用的导入的快捷键,但可以删除android studio中重新格式代码中未使用的导入.

编辑1:

我在寻找:重新格式化code.reformat代码选项时通常可以找到删除未使用的导入的选项 Preferences->Editor->Code Style->Java

android android-studio

6
推荐指数
2
解决办法
8717
查看次数

onChange TextField移动光标以开始抖动

我尝试用中的onChange方法检查输入,TextField但用TextEditingController光标替换文本后将其移动到的开始TextField

仅在Android平台上会出现此问题。

TextField(
controller: textEditController,
onChanged: (content) {
                    textEditController.text = checkNumber(content);
                  },)
Run Code Online (Sandbox Code Playgroud)

扑扑版

[?] Flutter (Channel master, v1.2.2-pre.41, on Mac OS X 10.14.3 18D109, locale
    en-IR)
[?] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
Run Code Online (Sandbox Code Playgroud)

textfield flutter

5
推荐指数
3
解决办法
3200
查看次数

FutureBuilder Flutter 中未处理的异常

我尝试使用FutureBuilder小部件flutter从网络中获取一些数据。为此,我使用以下代码:

Future<List<Product>> getWishList() async {
http.Response response = await http.post(
  MY_URL,
  headers: {
    HttpHeaders.acceptHeader: 'application/json',
    HttpHeaders.contentTypeHeader: 'application/json; charset=utf-8'
  },
);
if (response.statusCode == 200) {
  List<Product> ret = List();
  Map<String, dynamic> result;
  try {
    result = json.decode(response.body);
    for (var i = 0; i < result['data'].length; i++) {
        ret.add(Product.fromJson(result['data'][i]));
    }
    return ret;
  } catch (e) {
    return throw Exception("Json parse error");
  }
} else {
  return throw Exception("network connection failed");
}
}
Run Code Online (Sandbox Code Playgroud)

和:

FutureBuilder(
            future: getWishList(),
            builder: …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

在Dart中将英语数字与波斯语数字转换

我在新的Dartflutter

我想用波斯数字代替英文数字。如何实现呢?

1-2-3-4-5-6-7-8-9 ==> ???-?-?-?-?-?-?-?-?
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

kotlin + 改造 + 协程 + androidTest

如何androidTest为样品retrofit请求创建?

样本

data class TestDataClass(
    val id: String,
    val employee_name: String,
    val employee_salary: String,
    val employee_age: String,
    val profile_image: String)

enum class NetworkState { LOADING, ERROR, DONE }

private const val BASE_URL = "http://dummy.restapiexample.com/api/v1/"

private val moshi = Moshi.Builder()
    .add(KotlinJsonAdapterFactory())
    .build()



private val retrofit = Retrofit.Builder()
    .addConverterFactory(MoshiConverterFactory.create(moshi))
    .addCallAdapterFactory(CoroutineCallAdapterFactory())
    .baseUrl(BASE_URL)
    .build()

interface TestApiService {
    @GET("employees")
    fun getPropertiesAsync():
            Deferred<List<TestDataClass>>
}

object TestApi {
    val retrofitTest : TestApiService by lazy { retrofit.create(TestApiService::class.java) }
}
Run Code Online (Sandbox Code Playgroud)

android android-testing android-jetpack

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