链表是什么

链表了解吗

  • Linked list is a sequence of links which contains items

  • Link - Each link of a linked list can store a data called an element

  • Next - Each link of a linked list contains a link to the next link called Next

  • LinkedList - A Linked List contains the connection link to the first link called First

  • Linked list can be visualized as a chain of nodes,where every node points to hte next node

    ![image](Linked List

    • Simple linked list -item navigation is forward only
    • doubly linked list - items can be navigated forward and backward
    • circular linked list - last item contains link of the first element as next and the first element has a link to the last element as previous.

双向链表是什么

同上,节点有前后指针

跟数组的区别

  • 数组在编译时已经分配好连续内存
  • 链表在运行时添加数据时分配内存
  • 数组在栈,链表在堆

数组为什么快

  • 数组查找快,因为可以根据索引直接获得,复杂度O(1),链表复杂度O(N)
  • 数组插入和删除慢,因为空间连续,插入删除后需要整理内存大小,链表插入删除快,只要改变指针指向即可

参考:1. https://www.tutorialspoint.com/data_structures_algorithms/linked_list_algorithms.htm

2.https://www.studytonight.com/data-structures/linked-list-vs-array

hexo给目录分类

创建分类功能

1
hexo new page categories

打开index文件

1
/source/categories/index.md

文件添加字段

1
2
3
title: categories
date: 2021-01-05 12:19:59
type: "categories"

写文章的时候加上分类标签

1
2
3
4
5
title: mac android studio flutter 打包 apk
date: 2020-11-16 20:16:07
categories:
- unix
tags:

添加标签同理

完。

参考:https://www.cnblogs.com/hankleo/p/11606224.html

flutter中的websocket概念

目的:实现客户端与服务端的实时通讯,基于TCP协议

与keep-alive区别:keep-alive机制会连接一小段时间,最终会断开,ws协议不会断开

原理:通过一条特殊的http协议请求进行握手后,服务端支持ws协议,则进行协议升级,利用http创建的tcp连接,实现长连接。

步骤分解:

  • 连接服务器

    1
    final channel = IOWebSocketChannel.connect('ws://echo.websocket.org');
  • 关闭连接

    1
    channel.sink.close();
  • 监听服务器

    • StreamBuilder是一个组件,收到一个stream就刷新界面
    1
    2
    3
    4
    5
    6
    new StreamBuilder(
    stream: widget.channel.stream,
    builder: (context, snapshot) {
    return new Text(snapshot.hasData ? '${snapshot.data}' : '');
    },
    );
  • 发送消息

    1
    channel.sink.add('Hello!');

完整demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import 'package:flutter/material.dart';
import 'package:web_socket_channel/io.dart';

class WebSocketRoute extends StatefulWidget {
@override
_WebSocketRouteState createState() => new _WebSocketRouteState();
}

class _WebSocketRouteState extends State<WebSocketRoute> {
TextEditingController _controller = new TextEditingController();
IOWebSocketChannel channel;
String _text = "";


@override
void initState() {
//创建websocket连接
channel = new IOWebSocketChannel.connect('ws://echo.websocket.org');
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("WebSocket(内容回显)"),
),
body: new Padding(
padding: const EdgeInsets.all(20.0),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Form(
child: new TextFormField(
controller: _controller,
decoration: new InputDecoration(labelText: 'Send a message'),
),
),
new StreamBuilder(
stream: channel.stream,
builder: (context, snapshot) {
//网络不通会走到这
if (snapshot.hasError) {
_text = "网络不通...";
} else if (snapshot.hasData) {
_text = "echo: "+snapshot.data;
}
return new Padding(
padding: const EdgeInsets.symmetric(vertical: 24.0),
child: new Text(_text),
);
},
)
],
),
),
floatingActionButton: new FloatingActionButton(
onPressed: _sendMessage,
tooltip: 'Send message',
child: new Icon(Icons.send),
),
);
}

void _sendMessage() {
if (_controller.text.isNotEmpty) {
channel.sink.add(_controller.text);
}
}

@override
void dispose() {
channel.sink.close();
super.dispose();
}
}

数据类型:发送的过程中数据以frame形式存在,每一个frame都由opcode字段指定类型,客户端在收到消息时已经知道类型,会自动转换,streamBuilder.snapshot.data如果是文本,类型是string,二进制数据,类型是List,还有其他类型

参考:https://book.flutterchina.club/chapter11/websocket.html

flutter中一个好用的三方库loading

地址:https://github.com/kokohuang/flutter_easyloading

用法,添加到materialApp的builder属性中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter EasyLoading',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter EasyLoading'),
builder: EasyLoading.init(),
);
}
}

接下来在任何地方调用

1
2
3
4
5
6
7
8
9
10
11
12
13
EasyLoading.show(status: 'loading...');

EasyLoading.showProgress(0.3, status: 'downloading...');

EasyLoading.showSuccess('Great Success!');

EasyLoading.showError('Failed with Error');

EasyLoading.showInfo('Useful Information.');

EasyLoading.showToast('Toast');

EasyLoading.dismiss();

示例图片

image

flutter padding组件

如果一个组件没有调整内边距的属性,那么可以在它的外层加一层Padding,达到调整位置的效果,效果等同于放到Container里,比Container更轻量级

1
2
3
4
Padding(
padding: EdgeInsets.all(10),
child: Text('这是一段测试文字'),
)

flutter ListTitle组件

该组件可以用在container和card组件里,默认有大标题和小标题属性,无需再进行text上下排列组合

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Card(
margin: EdgeInsets.all(10),
child: Column(
children: <Widget>[
ListTile(
title: Text("张三",style: TextStyle(fontSize: 28)),
subtitle: Text("董事长"),
),
Divider(),
ListTile(
title: Text("电话:123456789"),
),
ListTile(title: Text("地址:xxxxxxxxxxxxxxxxx"))
],
),
),

image

flutter card组件

在开发过程中,Container组件使用多了,会有一些重复的代码,比如矩形边框和圆角,需要额外加decoration,使用card已经默认加上了边框和阴影

1
2
3
4
Card(
margin: EdgeInsets.all(10),
child: ...
)

flutter中radio单选使用

在一个数组容器里放置两个及其以上radio,当radio的group value和自己value相等时,便是选中状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int groupValue = 1;
_onChange(value){
if(mounted)
setState(() {
groupValue = value;
});
}

Row(

mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Radio(
value: 1,
groupValue: groupValue,
onChanged: (T) => _onChange(T),
),
Radio(
value: 2,
groupValue: groupValue,
onChanged: (T) => _onChange(T),
),
Radio(
value: 3,
groupValue: groupValue,
onChanged: (T) => _onChange(T),
),
],
)

参考:https://blog.csdn.net/zhangwes/article/details/104978660