我尝试在构造函数中使用一些参数创建一些自定义小部件。该小部件具有一些可选的和必需的参数。如何使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) 我知道Ctrl+Shift+O
删除未使用的导入的快捷键,但可以删除android studio中重新格式代码中未使用的导入.
编辑1:
我在寻找:重新格式化code.reformat代码选项时通常可以找到删除未使用的导入的选项 Preferences->Editor->Code Style->Java
我尝试用中的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) 我尝试使用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
。
我想用波斯数字代替英文数字。如何实现呢?
1-2-3-4-5-6-7-8-9 ==> ???-?-?-?-?-?-?-?-?
Run Code Online (Sandbox Code Playgroud) 如何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)