如何检查flutter textfield 是否包含unicode字符

string.codeUnits is an array of Unicode UTF-16 code units. So i would say it could be like

int maxLengthOfTextField(String text){
  final int maxBits = 128;
  List<int> unicodeSymbols = text.codeUnits.where((ch) => ch > maxBits ).toList();
  return unicodeSymbols.length > 0 ? 160 : 70;
}

final textFieldController = TextEditingController();
TextField(
  controller: textFieldController,
  maxLength: maxLengthOfTextField(textFieldController.text)
);

 

来源于网站: https://stackoverflow.com/questions/55607305/how-can-i-check-if-a-textfield-contains-unicode-characters-in-flutter-dart

 

修改后成为:

            child: TextField(
                decoration: InputDecoration(
                  hintStyle: TextStyle(fontSize: 17),
                  hintText: 'Search your trips',
                  // suffixIcon: Icon(Icons.search),
                  counterText: "",
                  border: InputBorder.none,
                  contentPadding: EdgeInsets.all(20),
                ),
                maxLength: 480,
                controller: textController,
                onChanged: _onChanged,
              ),

 

  _onChanged(String value) {
    // print(value);
    final int maxBits = 128;
    List<int> unicodeSymbols = value.codeUnits.where((ch) => ch > maxBits ).toList();
    if(unicodeSymbols.length > 0)
    {
      setState(() {
        ifContainUnicode = "unicode";
      });
    }
    else
    {

      setState(() {
        ifContainUnicode = "bit";
      });
    }

    setState(() {
      charLength = value.length;
    });
  }

 

这个网址也可以看一下; https://dev.to/stack-labs/flutter-utf8-textfield-length-limiter-and-char-counter-31o7

如何用flutter做web

  • flutter config --enable-web

这个命令是启动web 开发

  • 查看当前channel
flutter channel 
  • 切换channel
flutter channel masters
  • 顺序是:先切换channel 再启动web
  • 左边导航条怎么实现子菜单

https://stackoverflow.com/questions/45559580/expansion-panel-list-in-flutter

  • 怎么在网页上画图表

https://whereisdarran.com/2020/02/charts-for-flutter-and-flutter-web/

  • 怎么执行js

https://medium.com/flutter-community/using-javascript-code-in-flutter-web-903de54a2000

https://fireship.io/snippets/using-js-with-flutter-web/

 

  • 画table 和 带换页的table

https://medium.com/codechai/flutter-web-and-paginateddatatable-3779da7683e

 

  • 怎么画bootstrap 风格的页面
bootstrap就是指 网页能随着缩放拉伸,自动适应设备的大小, 布局可能随页面的大小而变
用这个package :  responsive_builder: ^0.3.0
————–
以下是仿 movider

python how to cal math

  • numpy生成随机数:

a = np.random.randint(0,20,(5,))

在0和20之间生成5个随机整数


计算刚才生成数组的梯度 (gradient)

np.gradient(a)


梯度能看作导数吗?  不能

  • 导数 : Derivative

可以用numpy计算, 也能用sympy

python 怎么计算导数 :   要算导数,首先要有函数,对于时间序列,并没有拟合函数,似乎也没必要有

 

 

 

怎么用python画柱状k线

来源: https://www.programmersought.com/article/17884763118/

 

import matplotlib.dates
from matplotlib.dates import date2num
import datetime as dt

from matplotlib import pyplot as plt
from mplfinance.original_flavor import candlestick_ohlc
import random


# start="2020-1-1"
# data=[]

# day=date2num(dt.datetime.strptime(start,'%Y-%m-%d'))

# one=(day,15110,15065,15140,15035) 
# print(day)
# print(one)


# fig,ax=plt.subplots(facecolor="white",figsize=(12,8))
# fig.subplots_adjust(bottom=0.1)
# ax.xaxis_date()
# plt.xticks(rotation=30)
# plt.title('K-line')
# plt.xlabel('time')
# plt.ylabel('price')
# candlestick_ohlc(ax,data,width=0.5,colorup='r',colordown='green') 
# plt.grid(True)



start="2020-1-1"
data=[]
for i in range(31):    
    random_data=[random.randint(2000,2500) for _ in range(4)]
    sorted_data=sorted(random_data)
    day=date2num(dt.datetime.strptime(start,'%Y-%m-%d'))
    # print(day)
    if i==0:
        one=(day,sorted_data[1],sorted_data[3],sorted_data[0],sorted_data[2]) if random.random()>0.5 else (day,sorted_data[2],sorted_data[3],sorted_data[0],sorted_data[1])       
    else:
        one=(day+i,sorted_data[1],sorted_data[3],sorted_data[0],sorted_data[2]) if random.random()>0.5 else (day+i,sorted_data[2],sorted_data[3],sorted_data[0],sorted_data[1])
    data.append(one)

print(data)
fig,ax=plt.subplots(facecolor="white",figsize=(12,8))
fig.subplots_adjust(bottom=0.1)
ax.xaxis_date()
plt.xticks(rotation=30)
plt.title('K-line')
plt.xlabel('time')
plt.ylabel('price')
candlestick_ohlc(ax,data,width=0.5,colorup='r',colordown='green') 
plt.grid(True)
plt.show()



 

 

Mac Big Sur 版本怎么编辑配置文件

  • 首先弄清用的什么shell
echo $SHELL

这个命令在本机的输出是: /bin/zsh

所以shell 是 zsh

  • The ~/ translates to your user’s home directory and the .zshrc is the ZSH configuration file itself.

所以, 执行:

nano ~/.zshrc
  • 编辑之后, 如果想让修改生效 ,执行:
exec "$SHELL"

 

windows 10 , MAC Big Sur 安装 pytorch 1.4 cpu 版本

  •  python需要 3.8.6 这个版本, 必须精确
  • 因为当前台式机是amd显卡, 所以用不了 nvadia cuda  , 只能直接安装cpu版本
  • 网上有很多例子提出用清华或者阿里镜像 , 方法是 :
    pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html -i http://mirrors.aliyun.com/pypi/simple/

     

    实测速度并不好 ,

  • 最终的解决方法是先fq ,然后设置 command line 代理 :
set HTTP_PROXY=http://127.0.0.1:1080

set HTTPS_PROXY=http://127.0.0.1:1080

然后去掉上面安装命令 包括 -i 及之后的部分, 执行即可

 


For Mac Big Sur

https://zhuanlan.zhihu.com/p/168748757

mac os BIG SUR how to 安装python多个版本

  • 先安装  brew
  • brew install pyenv

     

  • pyenv install 3.6.7

     

    在这一步失败, 因为mac os BIG SUR 不能安装3.6.7版本, 有人也同样这个问题, 目前没解决方法

 

BIG SUR 只能安装 python 3.9.1版本 , 但是问题是: python3.9.1过于新 , 很多库还不支持这个版本