Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加简单路由模块 & 文件改名 #1

Merged
merged 1 commit into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'AppTranslations.dart';
import 'Application.dart';
import 'app_translations.dart';
import 'application.dart';

class AppTranslationsDelegate extends LocalizationsDelegate<AppTranslations> {
final Locale newLocale;
Expand Down
50 changes: 25 additions & 25 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
//语言包实例化
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:efox_flutter/lang/Application.dart';
import 'package:efox_flutter/lang/AppTranslationsDelegate.dart';
import 'package:efox_flutter/lang/application.dart';
import 'package:efox_flutter/lang/app_translations_delegate.dart';
//引用Store 层
import 'package:efox_flutter/store/STORE.dart';
//模块加载
import 'package:efox_flutter/page/HomePage.dart';
import 'package:efox_flutter/store/store.dart';
//路由
import 'package:efox_flutter/router/index.dart';

void main() => runApp(MainApp());

Expand Down Expand Up @@ -41,25 +41,25 @@ class MainAppState extends State<MainApp> {
return STORE.init(
model: model,
child: MaterialApp(
localeResolutionCallback: (deviceLocale, supportedLocales) {
print(
'deviceLocale=$deviceLocale supportedLocales=$supportedLocales');
return deviceLocale ?? Locale('en');
},
localizationsDelegates: [
_newLocaleDelegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('zh'),
],
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
));
localeResolutionCallback: (deviceLocale, supportedLocales) {
print(
'deviceLocale=$deviceLocale supportedLocales=$supportedLocales');
return deviceLocale ?? Locale('en');
},
localizationsDelegates: [
_newLocaleDelegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en'),
const Locale('zh'),
],
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/',
routes: getRoutesConfig(context)));
}
}
14 changes: 12 additions & 2 deletions lib/page/HomePage.dart → lib/page/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:efox_flutter/lang/Application.dart';
import 'package:efox_flutter/lang/AppTranslations.dart';
import 'package:efox_flutter/lang/application.dart';
import 'package:efox_flutter/lang/app_translations.dart';
//
import 'package:efox_flutter/store/STORE.dart';

Expand Down Expand Up @@ -53,6 +53,16 @@ class HomePage extends StatelessWidget {
model.userInfo.age.toString(),
style: Theme.of(context).textTheme.display1,
),
RaisedButton(
child: Text('go test 1'),
onPressed: () =>
Navigator.pushNamed(context, '/test/test_page_one'),
),
RaisedButton(
child: Text('go test 2'),
onPressed: () =>
Navigator.pushNamed(context, '/test/test_page_two'),
)
],
),
),
Expand Down
15 changes: 15 additions & 0 deletions lib/page/test/test_page_one.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';

class TestPageOne extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('test page one'),
),
body: Center(
child: Text('test pahe pne'),
),
);
}
}
15 changes: 15 additions & 0 deletions lib/page/test/test_page_two.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';

class TestPageTwo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('test page two'),
),
body: Center(
child: Text('test pahe two'),
),
);
}
}
13 changes: 13 additions & 0 deletions lib/router/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/widgets.dart';
//首页
import 'package:efox_flutter/page/home_page.dart';

//测试路由配置
import 'package:efox_flutter/router/test/index.dart';

Map<String, WidgetBuilder> getRoutesConfig(BuildContext context) {
Map<String, WidgetBuilder> finalMap = {};
finalMap.addAll({'/': (context) => HomePage()});
finalMap.addAll(getTestRoutesConfig(context));
return finalMap;
}
11 changes: 11 additions & 0 deletions lib/router/test/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:flutter/widgets.dart';

import 'package:efox_flutter/page/test/test_page_one.dart';
import 'package:efox_flutter/page/test/test_page_two.dart';

Map<String, WidgetBuilder> getTestRoutesConfig(BuildContext context) {
return {
'/test/test_page_one': (context) => TestPageOne(),
'/test/test_page_two': (context) => TestPageTwo()
};
}
4 changes: 2 additions & 2 deletions lib/store/STORE.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:scoped_model/scoped_model.dart';
import './models/MainStateModel.dart';
export './models/MainStateModel.dart';
import './models/main_state_model.dart';
export './models/main_state_model.dart';

class STORE {
static init({model, child}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:scoped_model/scoped_model.dart';
import 'UserModel.dart';
import 'user_model.dart';

///主数据模型,需要全局使用的数据在这里添加模型
class MainStateModel extends Model with UserModel {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:scoped_model/scoped_model.dart';
import '../objects/UserInfo.dart';
import '../objects/user_info.dart';

class UserModel extends Model {
UserInfo _userInfo = UserInfo();
Expand All @@ -11,7 +11,6 @@ class UserModel extends Model {
}

Function setAge() {
//_userInfo.age += 1;
_userInfo.age += 1;
notifyListeners();
}
Expand Down
File renamed without changes.
File renamed without changes.