Write the Code. Change the World.

7月 16

随着苹果 8 以后的手机等出现,顶部,底部自适应问题是手机应用(app,web,小程序)要解决的问题。对于网页和小程序可以使用 env(safe-area-inset-bottom) 等解决。

env()和constant(),是IOS11新增特性,Webkit的css函数,用于设定安全区域与边界的距离,有4个预定义变量:

  • safe-area-inset-left:安全区域距离左边边界的距离
  • safe-area-inset-right:安全区域距离右边边界的距离
  • safe-area-inset-top:安全区域距离顶部边界的距离
  • safe-area-inset-bottom :安全距离底部边界的距离

而env()和constant()函数有个必要的使用前提,H5网页设置viewport-fit=cover的时候才生效,小程序里的viewport-fit默认是cover。

<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">

适配底部代码:

height: calc(96rpx+ constant(safe-area-inset-bottom));//兼容 IOS<11.2

height: calc(96rpx + env(safe-area-inset-bottom));//兼容 IOS>11.2

padding-bottom: constant(safe-area-inset-bottom);//兼容 IOS<11.2

padding-bottom: env(safe-area-inset-bottom);//兼容 IOS>11.2


// 先constant再env

文章来源第二个有说到兼容性问题。

文章来源

https://www.cnblogs.com/djjlovedjj/p/13983852.html

https://www.cnblogs.com/djjlovedjj/p/14686684.html

阅读全文 >>

7月 09

Text(
    '给我一个理由忘记',
    overflow: TextOverflow.ellipsis,
    maxLines: 2,
    style: TextStyle(
        fontSize: 13.0
    ),
)

在某些场景下无法换行,请用 Expanded

Expanded (
    child: Text(
        '给我一个理由忘记',
        overflow: TextOverflow.ellipsis,
        maxLines: 2,
        style: TextStyle(
            fontSize: 13.0
        ),
    )
)

也可以套 Container ,设置宽度来限制文本的宽度。

阅读全文 >>

7月 09

准备

https://github.com/FriendsOfPHP/Goutte

https://github.com/guzzle/guzzle

https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html

安装

composer require fabpot/goutte

composer require guzzlehttp/guzzle

试试

先看看 goutte

use Goutte\Client;

$client = new Client();
$crawler = $client->request('GET', 'https://www.yuepaibao.com/moments');
$crawler->filter('.content span')->each(function ($node) {
print $node->text()."\n";
});

**再看看 GuzzleHttp **

use GuzzleHttp\Client as GoutteClient;
use GuzzleHttp\Psr7\Request as GuzzleRequest;

$url = 'https://www.hao123.com';
$request = new GuzzleRequest('GET', $url);
$client = new GoutteClient();
$response = $client->send($request, ['timeout' => 5]);
$content = $response->getBody()->getContents();
echo $content;

特殊

https://learnku.com/laravel/t/3590/php-crawls-the-page-that-needs-to-run-js-run-js-grabing-web-page-with-php-while

阅读全文 >>

6月 18

领离药房

https://github.com/vjiedan/shwinking.git

万敬
https://github.com/vjiedan/shwinking.git

高锶
git@gitlab.com:vinish/gaosi.com.git

ssl 证书
https://github.com/prispace/sslcer.git

溯源码
https://github.com/vjiedan/suyuanma.git

约拍宝-v2服务端
https://gitlab.com/vinish/yuepaibao.git

约拍宝-v1服务端
https://gitlab.com/yuepaibao/www.yuepaibao.com.git

阅读全文 >>

6月 03

mysql 事务里,没有使用 commit。导致该资源被长期占用,其他事务在抢占该资源时,因上一个事务的锁而导致抢占失败。

处理

方法一
- 查看事物表,找出被锁线程的id:SELECT * FROM information_schema.INNODB_TRX;
- 根据 id(trx_mysql_thread_id),kill掉被锁住的线程:kill 121212

方法二
- 执行MySQL命令:SHOW FULL PROCESSLIST; 找到被锁住的线程ID
- 根据id,kill掉被锁住的线程:kill 4

阅读全文 >>

5月 21

一套完善编码规范很重要。 php-cs-fixer 可一键把代码格式化为 PSR-2 标准。 php-cs-fixer 可单独使用,也可以结合编辑器使用。

github: https://github.com/FriendsOfPHP/PHP-CS-Fixer

操作一波

下载并设置权限

cd /usr/local/bin

wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -O php-cs-fixer 

chmod +x php-cs-fixer

使用

# 格式化当前目录下代码 
php-cs-fixer fix .

阅读全文 >>

4月 23

请看

  • 怎么设置样式
  • 怎么设置宽高 padding

https://blog.csdn.net/mengks1987/article/details/109480289

http://events.jianshu.io/p/ad231ab22cee

https://www.jianshu.com/p/5d24fd29ab8b

想要的东东

  • 设置按钮的 padding,margin 为 零
style: ButtonStyle(
    tapTargetSize: MaterialTapTargetSize.shrinkWrap,
    minimumSize: MaterialStateProperty.all(Size(0, 0)),
    padding: MaterialStateProperty.all(EdgeInsets.zero),
)
  • 设置形状
style: ButtonStyle(
    shape: MaterialStateProperty.all(RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10)))
)
  • 去掉阴影
style: ButtonStyle(
    shadowColor: MaterialStateProperty.all(Colors.transparent),
)
  • 去掉水波纹(去掉水波纹后,hove 等效果也没了)
style: ButtonStyle(
    splashFactory: NoSplash.splashFactory
)
  • 设置按钮内文字的样式
style: ButtonStyle(
    textStyle: MaterialStateProperty.all(TextStyle(fontSize: 16.0, color: Colors.white)),
)

整体啰嗦一遍:

const ButtonStyle({
  this.textStyle, //字体
  this.backgroundColor, //背景色
  this.foregroundColor, //前景色
  this.overlayColor, // 高亮色,按钮处于focused, hovered, or pressed时的颜色
  this.shadowColor, // 阴影颜色
  this.elevation, // 阴影值
  this.padding, // padding
  this.minimumSize, //最小尺寸
  this.side, //边框
  this.shape, //形状
  this.mouseCursor, //鼠标指针的光标进入或悬停在此按钮的[InkWell]上时。
  this.visualDensity, // 按钮布局的紧凑程度
  this.tapTargetSize, // 响应触摸的区域
  this.animationDuration, //[shape]和[elevation]的动画更改的持续时间。
  this.enableFeedback, // 检测到的手势是否应提供声音和/或触觉反馈。例如,在Android上,点击会产生咔哒声,启用反馈后,长按会产生短暂的振动。通常,组件默认值为true。
});

常规的配置就这样了:

   style: ButtonStyle(
    tapTargetSize: MaterialTapTargetSize.shrinkWrap,
    minimumSize: MaterialStateProperty.all(Size(0, 0)),
    padding: MaterialStateProperty.all(EdgeInsets.zero),
    shadowColor: MaterialStateProperty.all(Colors.transparent),
    backgroundColor: MaterialStateProperty.all(Color(0xFFECB34D)),
    textStyle: MaterialStateProperty.all(TextStyle(fontSize: 16.0, color: Colors.white)),
    // elevation: MaterialStateProperty.all(0),
    // splashFactory: NoSplash.splashFactory
  )

但是,通常,我们并不单独配,我们要配到主题里。这样,在逻辑的其他地方,只需要简单的使用 button 就可以了。先配置在主题里。

ThemeData lightTheme = ThemeData.light().copyWith(
    elevatedButtonTheme: ElevatedButtonThemeData(
          style: ButtonStyle(
        tapTargetSize: MaterialTapTargetSize.shrinkWrap,
        minimumSize: MaterialStateProperty.all(Size(0, 0)),
        padding: MaterialStateProperty.all(EdgeInsets.zero),
        shadowColor: MaterialStateProperty.all(Colors.transparent),
        backgroundColor: MaterialStateProperty.all(Color(0xFFECB34D)),
        textStyle: MaterialStateProperty.all(TextStyle(fontSize: 16.0, color: Colors.white)),
        // elevation: MaterialStateProperty.all(0),
        // splashFactory: NoSplash.splashFactory
      ))
);

使用的时候:

SizedBox(
    width: 120,
    height: 40,
    child: ElevatedButton(
        onPressed: () {
        },
        child: Text(
        "我是按钮",
        ),
    ))

如果想覆盖或增加主题的设置:
比如,这里加了一个 borderradius 。

SizedBox(
    width: 120,
    height: 40,
    child: ElevatedButton(
    style: ButtonStyle()
                                .copyWith(shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)))),
        onPressed: () {
        },
        child: Text(
        "我是按钮",
        ),
    ))

最后加一条。想让按钮自适应父容器。可以这个弄。

Container(
    width: 750,
    child: SizedBox(
        width: double.infinity,
        height: 92,
        child: ElevatedButton()
    )
)

SizedBox 能具体定义按钮的宽高,而 double.infinity 又不能突破 Container 的宽高。通常 Container 不是具体的宽高才会用到这种自适应的方式。

阅读全文 >>

4月 19

照片访问等

ios:

<key>NSCameraUsageDescription</key>
<string>Example usage description</string>
<key>NSMicrophoneUsageDescription</key>
<string>Example usage description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Example usage description</string>

android:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

阅读全文 >>