Initial commit

This commit is contained in:
toly
2023-04-16 10:28:45 +08:00
commit a1465d4a52
139 changed files with 5073 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
void main() {
foo4();
}
void foo1() {
List<int> numList = [1, 9, 9, 4, 3, 2, 8];
int second = numList[1];
print(second);
numList[3] = 6;
print(numList);
}
void foo2() {
List<int> numList = [1, 9, 9, 4, 3, 2, 8];
numList.add(10);
numList.insert(0, 49);
print(numList);
}
void foo3() {
List<int> numList = [1, 9, 9, 4, 3, 2, 8];
numList.removeAt(2);
numList.remove(3);
numList.removeLast();
print(numList);
}
void foo4() {
List<int> numList = [1, 9, 9, 4,];
for (int i = 0; i < numList.length; i++) {
int value = numList[i];
print("索引:$i, 元素值:$value");
}
for(int value in numList){
print("元素值:$value");
}
}

37
test/aggregation/map.dart Normal file
View File

@@ -0,0 +1,37 @@
void main() {
foo3();
}
void foo1() {
Map<int, String> numMap = {
0: 'zero',
1: 'one',
2: 'two',
};
print(numMap);
numMap.remove(1);
print(numMap);
}
void foo2() {
Map<int, String> numMap = {
0: 'zero',
1: 'one',
2: 'two',
};
numMap[3] = 'three';
numMap[4] = 'four';
print(numMap);
}
void foo3() {
Map<int, String> numMap = {
0: 'zero',
1: 'one',
2: 'two',
};
numMap.forEach((key, value) {
print("${key} = $value");
});
}

30
test/aggregation/set.dart Normal file
View File

@@ -0,0 +1,30 @@
void main() {
foo3();
}
void foo1() {
Set<int> numSet = {1, 9, 9, 4};
print(numSet);
}
void foo2() {
Set<int> numSet = {1, 9, 4};
numSet.add(10);
numSet.remove(9);
print(numSet);
}
void foo3() {
Set<int> a = {1, 9, 4};
Set<int> b = {1, 9, 3};
print(a.difference(b));// 差集
print(a.union(b)); // 并集
print(a.intersection(b)); // 交集
}
void foo4() {
Set<int> numSet = {1, 9, 4};
for(int value in numSet){
print("元素值:$value");
}
}

149
test/grammer/base.dart Normal file
View File

@@ -0,0 +1,149 @@
void main() {
// ---->[break情景]----
for (int i = 0; i < 10; i++) {
if (i % 3 == 2) {
break; //直接跳出循环
}
print("i:$i"); //打印了01
}
// ---->[continue情景]----
for (int i = 0; i < 10; i++) {
if (i % 3 == 2) {
continue; //跳出本次循环,将进入下次循环
}
print("i:$i"); //打印了 0134679
}
}
void main13() {
int sum = 0;
int i = 0;
do {
sum += i;
print("$i 次执行,sum = $sum");
i = i + 1;
} while (i < 5);
}
void main12() {
int sum = 0;
int i = 0;
while (i < 5) {
sum += i;
print("$i 次执行,sum = $sum");
i = i + 1;
}
}
void main11() {
int sum = 0;
for (int i = 0; i < 5; i = i + 1) {
sum += i;
print("$i 次执行,sum = $sum");
}
}
void main10() {
String mark = 'A';
switch (mark) {
case 'A':
print("优秀");
break;
case 'B':
print("良好");
break;
case 'C':
print("普通");
break;
case 'D':
print("较差");
break;
case 'E':
print("极差");
break;
default:
print("未知等级");
}
}
void main9() {
double height = 1.18;
// 布尔值可以通过运算获得
bool free = height < 1.2;
if (free) {
print("可免费入园");
} else {
print("请购买门票");
}
}
// 逻辑运算符
void main8() {
// 公园是否开放
bool open = true;
// 公园是否开放
bool free = false;
// 公园是否免费开放
bool freeEnter = open && free;
}
// 算术运算符
void main7() {
print(1 > 2); //false 大于
print(1 < 2); //true 小于
print(1 == 2); //false 等于
print(1 != 2); //true 不等
print(10 >= 3); //true 大于等于
print(10 <= 3); //false 小于等于
}
// 比较运算符
void main6() {
print(1 + 2); //3 加
print(1 - 2); //-1 减
print(1 * 2); //2 乘
print(1 / 2); //0.5 除
print(10 % 3); //1 余
print(10 ~/ 3); //3 商
}
void main5() {
// 直接赋值
bool enable = true;
double height = 1.18;
// 布尔值可以通过运算获得
bool free = height < 1.2;
}
void main4() {
double a = 2.3;
double b = 4.5;
double c = 2.5;
double avg = (a + b + c) / 3;
String output = '$a,$b,$c 的平均值是$avg';
// String output = '$a,$b,$c 的平均值是${(a + b + c) / 3}';
print(output);
}
void main3() {
String hello1 = 'Hello, World!';
String hello2 = "Hello, Flutter!";
print(hello1 + hello2);
}
void main0() {
int age = 2;
double weight = 4.5;
}
void main1() {
double a = 2.3;
double b = 4.5;
double c = 2.5;
double avg = (a + b + c) / 3;
print(avg);
}

View File

@@ -0,0 +1,20 @@
void main() {
double toly = bmi(1.8, 70);
double ls = bmi(1.79, 65);
double wy = bmi(1.69, 50);
print("===toly:$toly===ls:$ls===wy:$wy===");
}
// void main() {
// double toly = 1.8 / (70 * 70);
// double ls = 1.79 / (65 * 65);
// double wy = 1.69 / (50 * 50);
// print("===toly:$toly===ls:$ls===wy:$wy===");
// }
double bmi(double height, double wight) {
// 具体算法
double result = wight / (height * height);
return result;
}

View File

@@ -0,0 +1,23 @@
void main() {
double toly = bmi(weight: 70, height: 1.8);
double ls = bmi(height: 1.79);
double wy = bmi(height: 1.69, weight: 50);
print("===toly:$toly===ls:$ls===wy:$wy===");
}
// void main() {
// double toly = 1.8 / (70 * 70);
// double ls = 1.79 / (65 * 65);
// double wy = 1.69 / (50 * 50);
// print("===toly:$toly===ls:$ls===wy:$wy===");
// }
double bmi({
required double height,
double weight = 65,
}) {
// 具体算法
double result = weight / (height * height);
return result;
}

View File

@@ -0,0 +1,20 @@
void main() {
double toly = bmi(70, 1.8);
double ls = bmi();
double wy = bmi(1.69);
print("===toly:$toly===ls:$ls===wy:$wy===");
}
// void main() {
// double toly = 1.8 / (70 * 70);
// double ls = 1.79 / (65 * 65);
// double wy = 1.69 / (50 * 50);
// print("===toly:$toly===ls:$ls===wy:$wy===");
// }
double bmi([double height = 1.79, double weight = 65]) {
// 具体算法
double result = weight / (height * height);
return result;
}

14
test/grammer/oop/01.dart Normal file
View File

@@ -0,0 +1,14 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
}
void main(){
Human toly = Human();
toly.name = "捷特";
toly.weight = 70;
toly.height = 180;
print("Human: name{${toly.name},weight:${toly.weight}kg,height:${toly.height}cm}");
}

12
test/grammer/oop/02.dart Normal file
View File

@@ -0,0 +1,12 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
Human(this.name,this.weight,this.height);
}
void main(){
Human toly = Human("捷特",70,180);
print("Human: name{${toly.name},weight:${toly.weight}kg,height:${toly.height}cm}");
}

52
test/grammer/oop/03.dart Normal file
View File

@@ -0,0 +1,52 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
Human(this.name, this.weight, this.height);
String info() {
return "Human: name{${name},weight:${weight}kg,height:${height}cm}";
}
}
void main() {
Human toly = Human("捷特", 70, 180);
print(toly.info());
Human ls = Human("龙少", 65, 179);
print(ls.info());
Human wy = Human("巫缨", 65, 179);
print(wy.info());
}

40
test/grammer/oop/04.dart Normal file
View File

@@ -0,0 +1,40 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
Human(this.name, this.weight, this.height);
double bmi() {
double result = weight / ((height/100) * (height/100));
return result;
}
String info() {
return "Human: name{${name},weight:${weight}kg,height:${height}cm}";
}
}
class Student extends Human {
final String school;
Student(
super.name,
super.weight,
super.height, {
required this.school,
});
@override
String info() {
String info = super.info() + "school: $school ";
return info;
}
}
void main() {
Student toly = Student("捷特", 70, 180,school: "安徽建筑大学");
print(toly.bmi());
print(toly.info());
}

30
test/widget_test.dart Normal file
View File

@@ -0,0 +1,30 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_first_station/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}