Skip to content

Commit

Permalink
添加示例Model
Browse files Browse the repository at this point in the history
  • Loading branch information
HxBreak committed Aug 11, 2018
1 parent 24e1117 commit b02a72f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
12 changes: 9 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class _MainScreenState extends State<MainScreen> with TickerProviderStateMixin {
appBar: state.basicScreenStatus == CommonPageStatus.DONE
? AppBar(
title: Text("${state.basicCurrentTitleString}"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.account_box),
onPressed: () {
Navigator.of(context).pushNamed("login");
},
)
],
)
: null,
bottomNavigationBar:
Expand All @@ -71,9 +79,7 @@ class _MainScreenState extends State<MainScreen> with TickerProviderStateMixin {
title: Text("${e['name']}")))
.toList()
..addAll(BasicScreenStateModel.basicLocalNavItems
.map((e) => BottomNavigationBarItem(
icon: Icon(Icons.table_chart),
title: Text("data")))
.map((e) => e.item)
.toList()),
)
: null);
Expand Down
6 changes: 3 additions & 3 deletions lib/models/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class BottomNavigationItem {
final Widget icon;
final BottomNavigationBarItem item;

const BottomNavigationItem(String text, Widget icon)
BottomNavigationItem({@required String text, @required Widget icon})
: text = text,
icon = icon;
// item = const BottomNavigationBarItem(title: Text(text), icon: icon);
icon = icon,
item = BottomNavigationBarItem(title: Text(text), icon: icon);
}
22 changes: 16 additions & 6 deletions lib/models/main_state_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import 'package:flutter/material.dart';
// PROFILE,
// }

///主数据模型,需要全局使用的数据在这里添加模型
class MainStateModel extends Model
with BaseModel, IndexScreenStateModel, BasicScreenStateModel {
with BaseModel, IndexScreenStateModel, BasicScreenStateModel //, AModel
{
MainStateModel() {
initApp();
}
Expand All @@ -27,11 +29,12 @@ abstract class BasicScreenStateModel extends BaseModel {
CommonPageStatus basicScreenStatus = CommonPageStatus.READY;
List basicScreenNavItems = [];
int _currentSelNav = 0;
static const List<BottomNavigationItem> basicLocalNavItems = const [
// BottomNavigationItem(icon: Icon(Icons.forum), title: "社区"),
// BottomNavigationBarItem(
// icon: Icon(Icons.account_circle), title: Text("用户")),
static final List<BottomNavigationItem> basicLocalNavItems = [
BottomNavigationItem(icon: Icon(Icons.forum), text: "社区"),
BottomNavigationItem(icon: Icon(Icons.account_circle), text: "用户"),
];

///当前选中的索引
int get basicCurrentSelNav => _currentSelNav;

int get basicNavItemCount =>
Expand All @@ -42,10 +45,11 @@ abstract class BasicScreenStateModel extends BaseModel {
notifyListeners();
}

///当前页面的标题文字
String get basicCurrentTitleString {
return _currentSelNav < basicScreenNavItems.length
? basicScreenNavItems[_currentSelNav]['name']
: "$basicNavItemCount";
: basicLocalNavItems[_currentSelNav - basicScreenNavItems.length]?.text;
}

Future initApp() {
Expand All @@ -60,3 +64,9 @@ abstract class BasicScreenStateModel extends BaseModel {
}).whenComplete(this.notifyListeners);
}
}

///继承自BaseModel的 类
class AModel extends BaseModel {
///变量命名规范
double amodelXXX = 0.0;
}
2 changes: 1 addition & 1 deletion lib/screens/profile_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'dart:ui';
import 'dart:ui' hide Image;

class ProfileScreen extends StatefulWidget {
@override
Expand Down

0 comments on commit b02a72f

Please sign in to comment.