Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
netrain_flutter_app
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
邹志胜
netrain_flutter_app
Commits
9524e4c1
Commit
9524e4c1
authored
Jul 14, 2021
by
窦文
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
view model?
parent
54d95d5c
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
192 additions
and
33 deletions
+192
-33
Demo2.dart
netrain_flutter_app/lib/douwen/Demo2.dart
+50
-0
BaseView.dart
netrain_flutter_app/lib/douwen/custom/BaseView.dart
+61
-0
BaseViewModel.dart
netrain_flutter_app/lib/douwen/custom/BaseViewModel.dart
+40
-0
EmptyPage.dart
netrain_flutter_app/lib/douwen/custom/EmptyPage.dart
+13
-0
ErrorPage.dart
netrain_flutter_app/lib/douwen/custom/ErrorPage.dart
+13
-0
ViewState.dart
netrain_flutter_app/lib/douwen/custom/ViewState.dart
+1
-0
demo1.dart
netrain_flutter_app/lib/douwen/demo1.dart
+0
-0
dwMain.dart
netrain_flutter_app/lib/douwen/dwMain.dart
+13
-33
pubspec.yaml
netrain_flutter_app/pubspec.yaml
+1
-0
No files found.
netrain_flutter_app/lib/douwen/Demo2.dart
0 → 100644
View file @
9524e4c1
import
'package:flutter/material.dart'
;
import
'package:flutter/src/widgets/framework.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:netrain_flutter_app/douwen/custom/BaseView.dart'
;
import
'package:netrain_flutter_app/douwen/custom/BaseViewModel.dart'
;
class
Demo2
extends
BaseView
{
Demo2
()
:
super
(
BaseViewModel
())
{
builder
=
(
context
,
value
,
child
)
=>
Container
(
child:
Column
(
children:
[
Row
(
children:
[
_item
(
"setNormal"
,
()
{
viewModel
.
setNormal
();
}),
_item
(
"setEmpty"
,
()
{
viewModel
.
setEmpty
();
}),
_item
(
"setError"
,
()
{
viewModel
.
setError
();
}),
],
),
setReplaceView
(
Row
(
children:
[
ValueListenableBuilder
(
valueListenable:
viewModel
.
num
,
builder:
(
context
,
value
,
child
)
=>
Text
(
"点击了
${viewModel.num.value}
次"
)),
ElevatedButton
(
onPressed:
()
{
viewModel
.
click
();
},
child:
Text
(
"点击"
))
],
)),
],
));
}
_item
(
String
title
,
VoidCallback
onPressed
)
{
return
Container
(
child:
RaisedButton
(
onPressed:
onPressed
,
child:
Text
(
title
),
),
);
}
}
netrain_flutter_app/lib/douwen/custom/BaseView.dart
0 → 100644
View file @
9524e4c1
import
'package:flutter/widgets.dart'
;
import
'package:netrain_flutter_app/douwen/custom/BaseViewModel.dart'
;
import
'package:provider/provider.dart'
;
import
'EmptyPage.dart'
;
import
'ErrorPage.dart'
;
import
'ViewState.dart'
;
class
BaseView
extends
StatefulWidget
{
BaseViewModel
viewModel
;
Widget
Function
(
BuildContext
context
,
BaseViewModel
value
,
Widget
child
)
builder
;
Widget
_mReplaceView
;
Widget
emptyView
=
EmptyPage
();
Widget
errorView
=
ErrorPage
();
BaseView
(
this
.
viewModel
)
{
}
Widget
setReplaceView
(
Widget
replaceView
)
{
_mReplaceView
=
replaceView
;
switch
(
viewModel
.
viewState
??
ViewState
.
Normal
)
{
case
ViewState
.
Normal
:
return
_mReplaceView
;
case
ViewState
.
Empty
:
return
emptyView
;
case
ViewState
.
Error
:
return
errorView
;
case
ViewState
.
Loading
:
return
_mReplaceView
;
default
:
return
_mReplaceView
;
}
}
@override
State
<
StatefulWidget
>
createState
()
{
return
_BaseViewState
();
}
}
class
_BaseViewState
extends
State
<
BaseView
>
{
BaseViewModel
viewModel
;
@override
void
initState
()
{
viewModel
=
widget
.
viewModel
;
super
.
initState
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
ChangeNotifierProvider
(
create:
(
content
)
=>
viewModel
,
child:
Consumer
<
BaseViewModel
>(
builder:
widget
.
builder
,
),
);
}
}
netrain_flutter_app/lib/douwen/custom/BaseViewModel.dart
0 → 100644
View file @
9524e4c1
import
'package:flutter/widgets.dart'
;
import
'ViewState.dart'
;
class
BaseViewModel
with
ChangeNotifier
{
var
_viewState
;
var
num
=
ValueNotifier
<
int
>(
0
);
set
viewState
(
ViewState
viewState
)
=>
setViewState
(
viewState
);
get
viewState
=>
_viewState
;
void
click
()
{
num
.
value
=
(
num
.
value
??
0
)
+
1
;
num
.
notifyListeners
();
}
void
setNormal
()
{
viewState
=
ViewState
.
Normal
;
}
void
setEmpty
()
{
viewState
=
ViewState
.
Empty
;
}
void
setLoading
()
{
viewState
=
ViewState
.
Loading
;
}
void
setError
()
{
viewState
=
ViewState
.
Error
;
}
setViewState
(
ViewState
viewState
)
{
if
(
_viewState
==
viewState
)
{
return
;
}
_viewState
=
viewState
;
notifyListeners
();
}
}
netrain_flutter_app/lib/douwen/custom/EmptyPage.dart
0 → 100644
View file @
9524e4c1
import
'package:flutter/widgets.dart'
;
class
EmptyPage
extends
Container
{
@override
Widget
build
(
BuildContext
context
)
{
return
Center
(
child:
Container
(
child:
Text
(
"This is EmptyView"
),
),
);
}
}
\ No newline at end of file
netrain_flutter_app/lib/douwen/custom/ErrorPage.dart
0 → 100644
View file @
9524e4c1
import
'package:flutter/widgets.dart'
;
class
ErrorPage
extends
Container
{
@override
Widget
build
(
BuildContext
context
)
{
return
Center
(
child:
Container
(
child:
Text
(
"This is ErrorView"
),
),
);
}
}
\ No newline at end of file
netrain_flutter_app/lib/douwen/custom/ViewState.dart
0 → 100644
View file @
9524e4c1
enum
ViewState
{
Normal
,
Empty
,
Error
,
Loading
}
netrain_flutter_app/lib/douwen/demo1.dart
0 → 100644
View file @
9524e4c1
netrain_flutter_app/lib/douwen/dwMain.dart
View file @
9524e4c1
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:fluttertoast/fluttertoast.dart'
;
import
'package:netrain_flutter_app/common/Images.dart'
;
import
'package:netrain_flutter_app/common/Images.dart'
;
import
'package:netrain_flutter_app/douwen/custom/BaseView.dart'
;
import
'package:netrain_flutter_app/douwen/custom/BaseViewModel.dart'
;
import
'Demo2.dart'
;
import
'secondpage.dart'
;
import
'secondpage.dart'
;
void
main
(
)
{
void
main
(
)
{
...
@@ -14,6 +17,8 @@ void main() {
...
@@ -14,6 +17,8 @@ void main() {
class
MyApp
extends
StatelessWidget
{
class
MyApp
extends
StatelessWidget
{
// This widget is the root of your application.
// This widget is the root of your application.
BaseViewModel
viewModel
=
BaseViewModel
();
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
WillPopScope
(
return
WillPopScope
(
...
@@ -26,12 +31,14 @@ class MyApp extends StatelessWidget {
...
@@ -26,12 +31,14 @@ class MyApp extends StatelessWidget {
),
),
initialRoute:
"key1"
,
initialRoute:
"key1"
,
routes:
<
String
,
WidgetBuilder
>{
routes:
<
String
,
WidgetBuilder
>{
"key1"
:
(
context
)
=>
Scaffold
(
"key1"
:
(
context
)
=>
Scaffold
(
body:
Scaffold
(
appBar:
AppBar
(
appBar:
AppBar
(
title:
Text
(
"路由"
),
title:
Text
(
"这个是标题"
),
),
body:
RouterNavigator
(
title:
'Flutter Demo Home Page'
),
),
),
body:
Demo2
(),
)),
"key2"
:
(
context
)
=>
Second
()
"key2"
:
(
context
)
=>
Second
()
},
},
),
),
...
@@ -40,33 +47,6 @@ class MyApp extends StatelessWidget {
...
@@ -40,33 +47,6 @@ class MyApp extends StatelessWidget {
return
true
;
return
true
;
});
});
}
}
}
class
RouterNavigator
extends
StatefulWidget
{
RouterNavigator
({
Key
key
,
this
.
title
})
:
super
(
key:
key
);
final
String
title
;
@override
_RouterNavigatorState
createState
()
=>
_RouterNavigatorState
();
}
class
_RouterNavigatorState
extends
State
<
RouterNavigator
>
{
bool
byName
=
false
;
@override
Widget
build
(
BuildContext
context
)
{
return
Container
(
child:
Column
(
children:
[
_item
(
"跳转"
,
()
async
{
var
result
=
await
Navigator
.
push
(
context
,
MaterialPageRoute
(
builder:
(
context
)
=>
Second
()));
print
(
"返回值:
$result
"
);
}),
Image
.
asset
(
Images
.
bg_my_01
)
],
),
);
}
_item
(
String
title
,
VoidCallback
onPressed
)
{
_item
(
String
title
,
VoidCallback
onPressed
)
{
return
Container
(
return
Container
(
...
...
netrain_flutter_app/pubspec.yaml
View file @
9524e4c1
...
@@ -43,6 +43,7 @@ dependencies:
...
@@ -43,6 +43,7 @@ dependencies:
convert
:
^3.0.1
#转码器
convert
:
^3.0.1
#转码器
pull_to_refresh
:
^2.0.0
pull_to_refresh
:
^2.0.0
shared_preferences
:
^2.0.6
shared_preferences
:
^2.0.6
provider
:
^4.1.0
dev_dependencies
:
dev_dependencies
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment