美文网首页
flutter学习笔记

flutter学习笔记

作者: 蓝色的风 | 来源:发表于2020-10-27 11:55 被阅读0次

    1.全局隐藏键盘

    //全局隐藏键盘
    SystemChannels.textInput.invokeMethod('TextInput.hide');
    

    2.当前页面有多个textFiled的时隐藏键盘

     FocusScopeNode currentFocus = FocusScope.of(context);
      if (!currentFocus.hasPrimaryFocus &&
           currentFocus.focusedChild != null) {
           FocusManager.instance.primaryFocus.unfocus();
      }
    

    3. Row中设置每个widget的高度一致,使用IntrinsicHeight包裹Row即可

    4.设置text控件中文字的行间距

    Text('''我就是我一把首付款\n上来看房价市解放路世纪东\n隆盛科技放开老时间打开了福建烤老鼠\n杀戮空间放开老时间发\n萨拉的反馈和骄傲收到货了开始\n了UR我OK功能的时刻老姐过来撒娇鬼水平来看\n两岁呕吐交路口附近拉克丝荆防颗粒''',
      style: TextStyle(fontSize: 12,color: Colors.black,),
      strutStyle: StrutStyle(forceStrutHeight: true, height: 0.7, leading: 0.9),
    ),
    

    5.flutter apk 安卓安装无法访问网络

    添加访问网络的权限

        </application>
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    </manifest>
    

    6.There are multiple heroes that share the same tag within a subtree

    用一个组件中使用多个FloatingActionButton,必须设置heroTag(默认值为const _DefaultHeroTag(),),否则报错

     FloatingActionButton(
           heroTag: 'counter_increment',
           onPressed: ()=> context.read<CounterCubit>().increment(),
           child:const Icon(Icons.add,size: 20,),
        ),
      const SizedBox(height: 8,),
      FloatingActionButton(
         heroTag: 'counter_decrement',
         onPressed: ()=> context.read<CounterCubit>().decrement(),
          child:const Icon(Icons.remove,size: 20,),
     ),
    

    7.Flutter的textfield添加新的字符以后光标保持在最后

    //设置完显示的文字之后,还要设置selection
    textEditingController.text = nt;
    textEditingController.selection = TextSelection.fromPosition(TextPosition(offset: textEditingController.text.length));
    

    8.dart中list深拷贝和浅拷贝

    dart中list直接赋值给另一个list,修改其中一个list中的数据,之前的list也会发生变化,网上的三种方法

    1、直接赋值,
    2、重新构造对象,一个一个对象的进行填充
    3、使用List自带的generate方法创建出类似于深拷贝的对象
    

    实现下来还是会发生上面同样的问题,dart中提供了一个深拷贝的方法

    // start 默认为0, end不传,直接返回对应的数据
    List<E> sublist(int start, [int? end]);
    

    持续更新………………

    相关文章

      网友评论

          本文标题:flutter学习笔记

          本文链接:https://www.haomeiwen.com/subject/xlztvktx.html