Skip to content

Commit bb0fd89

Browse files
author
聂彬
committed
feat(): 模版模式的完成
1 parent 48b2b48 commit bb0fd89

File tree

7 files changed

+114
-1
lines changed

7 files changed

+114
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
18. 备忘录模式
2828
19. 观察者模式
2929
20. 状态模式
30-
21. 策略模式
30+
21. 策略模式
31+
22. 模版模式

lib/constant/string_const.dart

+3
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ class StringConst {
6767

6868
//策略模式
6969
static const String STRATEGY_ = "策略模式";
70+
71+
//模版模式
72+
static const String TEMPLATE_ = "模版模式";
7073
}

lib/main.dart

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:flutter_design/page/observer/observer_page.dart';
1717
import 'package:flutter_design/page/proxy/proxy_page.dart';
1818
import 'package:flutter_design/page/state/state_page.dart';
1919
import 'package:flutter_design/page/strategy/strategy_page.dart';
20+
import 'package:flutter_design/page/template/template_page.dart';
2021

2122
import 'constant/page_const.dart';
2223
import 'constant/string_const.dart';
@@ -57,6 +58,7 @@ class MyApp extends StatelessWidget {
5758
PageConst.OBSERVER_PAGE: (context) => ObserverPage(),
5859
PageConst.STATE_PAGE: (context) => StatePage(),
5960
PageConst.STRATEGY_PAGE: (context) => StrategyPage(),
61+
PageConst.TEMPLATE_PAGE: (context) => TemplatePage(),
6062
},
6163
);
6264
}

lib/page/home_page.dart

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Map<String, String> map = {
3636
PageConst.OBSERVER_PAGE: StringConst.OBSERVER_,
3737
PageConst.STATE_PAGE: StringConst.STATE_,
3838
PageConst.STRATEGY_PAGE: StringConst.STRATEGY_,
39+
PageConst.TEMPLATE_PAGE: StringConst.TEMPLATE_,
3940
};
4041

4142
class _HomePageState extends State<HomePage> {

lib/page/strategy/strategy_page.dart

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter_design/page/strategy/strategy_mode.dart';
34

@@ -83,6 +84,11 @@ class _StrategyPageState extends State<StrategyPage> {
8384
onPressed: () {
8485
_context.move = ByBus();
8586
_context.run();
87+
print("${Container(
88+
child: Text("Hello world"),
89+
).toStringDeep()}");
90+
ObserverList list = ObserverList();
91+
list.add("Hello world");
8692
},
8793
),
8894
],

lib/page/template/template_mode.dart

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/// Created by NieBin on 2020-04-16
2+
/// Github: https://github.com/nb312
3+
4+
abstract class IWork {
5+
void start();
6+
7+
void working();
8+
9+
void end();
10+
11+
void work() {
12+
start();
13+
working();
14+
end();
15+
}
16+
}
17+
18+
class NieBin extends IWork {
19+
@override
20+
void end() {
21+
print("加班后下班");
22+
}
23+
24+
@override
25+
void start() {
26+
print("从上海地铁站上站");
27+
}
28+
29+
@override
30+
void working() {
31+
print("进行Flutter开发");
32+
}
33+
}
34+
35+
class Other extends IWork {
36+
@override
37+
void end() {
38+
print("开开心心下班");
39+
}
40+
41+
@override
42+
void start() {
43+
print("从公司附近出发");
44+
}
45+
46+
@override
47+
void working() {
48+
print("进行前端开发");
49+
}
50+
}

lib/page/template/template_page.dart

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_design/page/template/template_mode.dart';
3+
4+
/// Created by NieBin on 2020-04-16
5+
/// Github: https://github.com/nb312
6+
7+
8+
class TemplatePage extends StatefulWidget {
9+
@override
10+
_TemplatePageState createState() => _TemplatePageState();
11+
}
12+
13+
class _TemplatePageState extends State<TemplatePage> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return Scaffold(
17+
appBar: AppBar(
18+
title: Text("模版模式"),
19+
),
20+
body: Container(
21+
child: Column(
22+
children: <Widget>[
23+
FlatButton(
24+
color: Colors.orange,
25+
child: Padding(
26+
padding: const EdgeInsets.all(8.0),
27+
child: Text("NieBin的工作日常"),
28+
),
29+
onPressed: () {
30+
NieBin nb = NieBin();
31+
nb.work();
32+
},
33+
),
34+
FlatButton(
35+
color: Colors.orange,
36+
child: Padding(
37+
padding: const EdgeInsets.all(8.0),
38+
child: Text("其他人的工作日常"),
39+
),
40+
onPressed: () {
41+
Other other = Other();
42+
other.work();
43+
},
44+
),
45+
],
46+
),
47+
),
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)