颤振 - 跨度不能为零长度

时间:2017-05-21 11:31:37

标签: android spannablestring flutter

我正在开发一个使用Textfield的Flutter应用程序

我正在声明TextField:

new TextField(
      controller : _controller,
      decoration : new InputDecoration(
        hintText: 'Message...'
    )
)

文本字段显示在我的窗口小部件中,但是当我点击它时,键盘会自动关闭,并且控制台中会出现以下错误

E/SpannableStringBuilder(17860): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

我在Android(Samsung Galaxy Grand Prime,Android 5.1)上使用IntelliJ中的Flutter插件运行它。

我怎么能解决这个问题?

编辑: 正如在这个答案(Android - SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length)上所看到的,我尝试过切换键盘(谷歌和三星),同样顺势而已

3 个答案:

答案 0 :(得分:1)

我认为完整的错误可能在其他地方。如果问题是针对一个Android设备的话,我建议打开一个新的颤动问题。

答案 1 :(得分:1)

对我来说,解决方法是添加seed = 0 numpy.random.seed(seed) X_train, y_train, X_test, y_test = CachedDatasets().load_dataset("Trace") X_train = X_train[y_train < 4] # Keep first 3 classes numpy.random.shuffle(X_train) # Keep only 50 time series X_train = TimeSeriesScalerMeanVariance().fit_transform(X_train[:50]) # Make time series shorter X_train = TimeSeriesResampler(sz=40).fit_transform(X_train) sz = X_train.shape[1] # Euclidean k-means print("Euclidean k-means") km = TimeSeriesKMeans(n_clusters=3, verbose=True, random_state=seed) y_pred = km.fit_predict(X_train) plt.figure() for yi in range(3): plt.subplot(3, 3, yi + 1) for xx in X_train[y_pred == yi]: plt.plot(xx.ravel(), "k-", alpha=.2) plt.plot(km.cluster_centers_[yi].ravel(), "r-") plt.xlim(0, sz) plt.ylim(-4, 4) plt.text(0.55, 0.85,'Cluster %d' % (yi + 1), transform=plt.gca().transAxes) if yi == 1: plt.title("Euclidean $k$-means") # DBA-k-means print("DBA k-means") dba_km = TimeSeriesKMeans(n_clusters=3, n_init=2, metric="dtw", verbose=True, max_iter_barycenter=10, random_state=seed) y_pred = dba_km.fit_predict(X_train) for yi in range(3): plt.subplot(3, 3, 4 + yi) for xx in X_train[y_pred == yi]: plt.plot(xx.ravel(), "k-", alpha=.2) plt.plot(dba_km.cluster_centers_[yi].ravel(), "r-") plt.xlim(0, sz) plt.ylim(-4, 4) plt.text(0.55, 0.85,'Cluster %d' % (yi + 1), transform=plt.gca().transAxes) if yi == 1: plt.title("DBA $k$-means") # Soft-DTW-k-means print("Soft-DTW k-means") sdtw_km = TimeSeriesKMeans(n_clusters=3, metric="softdtw", metric_params={"gamma": .01}, verbose=True, random_state=seed) y_pred = sdtw_km.fit_predict(X_train) for yi in range(3): plt.subplot(3, 3, 7 + yi) for xx in X_train[y_pred == yi]: plt.plot(xx.ravel(), "k-", alpha=.2) plt.plot(sdtw_km.cluster_centers_[yi].ravel(), "r-") plt.xlim(0, sz) plt.ylim(-4, 4) plt.text(0.55, 0.85,'Cluster %d' % (yi + 1), transform=plt.gca().transAxes) if yi == 1: plt.title("Soft-DTW $k$-means") plt.tight_layout() plt.show() ,并设置autocorrect: false这个错误发生在我的s8plus上,而我的iPhone模拟器却没有发生。

keyboardType: TextInputType.visiblePassword

答案 2 :(得分:0)

我有同样的错误。就我而言,问题不是TextFormField。这是因为Form小部件内的键。如果您使用键,则常规小部件必须是StatefulWidget,而不是StatelessWidget。

代码错误

class MyWidget extends StatelessWidget{
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); 
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Form(
        key: _formKey,
        child: TextFormField(),
      ),
    );
  }
}

权限代码

class MyWidget extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyWidgetState();
  }
}

class _MyWidgetState extends State<MyWidget>{
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); 
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Form(
        key: _formKey,
        child: TextFormField(),
      ),
    );
  }
}