Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f99a156

Browse files
authored
Merge pull request #16 from FlutterOpen/dev
feat(): 代理模式完成
2 parents d7b8b72 + 5682281 commit f99a156

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@
1515
8. 组合模式
1616
9. 装饰者模式
1717
10. 外观/门面模式
18-
11. 享元模式
18+
11. 享元模式
19+
12. 代理模式
20+
21+
### 行为型模式
22+
待添加

‎lib/constant/string_const.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ class StringConst {
3737

3838
//享元模式
3939
static const String FLYWEIGHT_ = "享元模式";
40+
41+
//享元模式
42+
static const String PROXY_ = "代理模式";
4043
}

‎lib/main.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter_design/page/decorator/decorator_page.dart';
77
import 'package:flutter_design/page/facade/facade_page.dart';
88
import 'package:flutter_design/page/filter/filter_page.dart';
99
import 'package:flutter_design/page/flyweight/flyweight_page.dart';
10+
import 'package:flutter_design/page/proxy/proxy_page.dart';
1011

1112
import 'constant/page_const.dart';
1213
import 'constant/string_const.dart';
@@ -37,6 +38,7 @@ class MyApp extends StatelessWidget {
3738
PageConst.DECORATOR_PAGE: (context) => DecoratorPage(),
3839
PageConst.FACADE_PAGE: (context) => FacadePage(),
3940
PageConst.FLYWEIGHT_PAGE: (context) => FlyweightPage(),
41+
PageConst.PROXY_PAGE: (context) => ProxyPage(),
4042
},
4143
);
4244
}

‎lib/page/home_page.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Map<String, String> map = {
2626
PageConst.DECORATOR_PAGE: StringConst.DECORATOR_,
2727
PageConst.FACADE_PAGE: StringConst.FACADE_,
2828
PageConst.FLYWEIGHT_PAGE: StringConst.FLYWEIGHT_,
29+
PageConst.PROXY_PAGE: StringConst.PROXY_,
2930
};
3031

3132
class _HomePageState extends State<HomePage> {

‎lib/page/proxy/proxy_mode.dart‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// Created by NieBin on 2020年03月27日
2+
/// Github: https://github.com/nb312
3+
/// Email: niebin312@gmail.com
4+
abstract class BuyProduct {
5+
void buyPhone();
6+
}
7+
8+
class BuyHuWei implements BuyProduct {
9+
@override
10+
void buyPhone() {
11+
print("购买华为手机");
12+
}
13+
}
14+
15+
class ProxyBuy implements BuyProduct {
16+
@override
17+
void buyPhone() {
18+
BuyProduct hua = BuyHuWei();
19+
hua.buyPhone();
20+
print("我爱中国?");
21+
}
22+
}

‎lib/page/proxy/proxy_page.dart‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_design/constant/string_const.dart';
3+
import 'package:flutter_design/page/proxy/proxy_mode.dart';
4+
5+
/// Created by NieBin on 2020年03月27日
6+
/// Github: https://github.com/nb312
7+
/// Email: niebin312@gmail.com
8+
9+
class ProxyPage extends StatefulWidget {
10+
@override
11+
_ProxyPageState createState() => _ProxyPageState();
12+
}
13+
14+
class _ProxyPageState extends State<ProxyPage> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return Scaffold(
18+
appBar: AppBar(
19+
title: Text(StringConst.PROXY_),
20+
),
21+
body: Container(
22+
child: Center(
23+
child: FlatButton(
24+
color: Colors.brown,
25+
child: Padding(
26+
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
27+
child: Text("购买手机"),
28+
),
29+
onPressed: () {
30+
BuyProduct product = ProxyBuy();
31+
product.buyPhone();
32+
},
33+
),
34+
),
35+
),
36+
);
37+
}
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /