Skip to content

Commit

Permalink
base state 重构ing...重构ing
Browse files Browse the repository at this point in the history
  • Loading branch information
bladeofgod committed Sep 9, 2020
1 parent f0703fe commit 1fb8188
Show file tree
Hide file tree
Showing 29 changed files with 387 additions and 445 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@


很简单,如下操作:
1、页面/wiget,继承Basestate/BaseStatelessWidget
1、页面/wiget,继承PageState/WidgetState/BaseStatelessWidget
2、骨架屏继承BaseSkeletonWidget
3、ViewModel(VM)继承 ViewStateModel的子类,如:SingleViewStateModel、RefreshListViewStateModel(也可以根据需求自己封装)
页面代码如下(页面请使用Basestate):
页面代码如下(页面请使用PageState):

class APageState extends BaseState<APage>{
class APageState extends PageState{
@override
Widget build(BuildContext context) {
return switchStatusBar2Dark(
Expand Down
239 changes: 124 additions & 115 deletions lib/base_framework/config/router_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,118 +49,127 @@ final RouteObserver<PageRoute> routeObserver = RouteObserver<PageRoute>();
/// 不过我不太喜欢这样用(该框架内也并没有这样使用)
final GlobalKey<NavigatorState> navigatorKey = GlobalKey();

class RouteName{

static const String demo_page = "demo_page";
static const String demo_exception_page = "demo_exception_page";
static const String main_page = 'main_page';
static const String login_page = 'login_page';
static const String pick_image_page = 'pick_image_page';
static const String demo_other_page = 'demo_other_page';
static const String scroll_page = 'scroll_page';
static const String little_util_page = 'little_util_page';
static const String slide_out_page = 'slide_out_page';
static const String timer_page = 'timer_page';
static const String permissions_page = 'permissions_page';
static const String ffloat_page = 'ffloat_page';
static const String cache_data_page = 'cache_data_page';
static const String update_page = 'update_page';

static const String route_anim_page = 'route_anim_page';
static const String fade_page = 'fade_page';
static const String scale_page = 'scale_page';
static const String slide_page = 'slide_page';

static const String local_i10l_page = 'local_i10l_page';

static const String isolate_page = 'isolate_page';


///对指定图片进行裁剪、并返回对应路径
static const String editor_image_page = "editor_image_page";
///显示大图
static const String show_big_image = "show_big_image";
///web/html
static const String web_page = 'web_page';
static const String html_page = 'html_page';

///dialog式progress
//static const String dialog_progress = 'dialog_progress';



}



class Router{

static Route<dynamic> generateRoute(RouteSettings settings){
switch(settings.name) {
case RouteName.isolate_page:
return pageBuilder.wrapWithNoAnim(IsolatePage());
case RouteName.update_page:
return pageBuilder.wrapWithNoAnim(UpdatePage());
case RouteName.demo_page:
///注意这个方法 :wrapAwareWidget()
///这样包裹后,页面的pop和push就可以监听到,具体怎么使用可以根据你的业务需求来 eg:页面恢复、统计等
///代码参见 :RouteAwareWidget 和日志
return pageBuilder.wrapWithNoAnim(wrapAwareWidget(RouteName.demo_page,DemoPage()));
case RouteName.scroll_page:
return pageBuilder.wrapWithNoAnim(ScrollPage());
case RouteName.cache_data_page:
return pageBuilder.wrapWithNoAnim(CacheDataPage());
case RouteName.little_util_page:
return pageBuilder.wrapWithNoAnim(LittleUtilPage());
case RouteName.ffloat_page:
return pageBuilder.wrapWithNoAnim(FFloatPage());
case RouteName.permissions_page:
return pageBuilder.wrapWithNoAnim(RequestPermissionsPage());
case RouteName.demo_other_page:
return pageBuilder.wrapWithNoAnim(OtherDemoPage());
case RouteName.local_i10l_page:
return pageBuilder.wrapWithNoAnim(LocalPage());
case RouteName.login_page:
return pageBuilder.wrapWithSlideTopAnim(LoginPage());
case RouteName.pick_image_page:
return pageBuilder.wrapWithNoAnim(PickImagePage());
case RouteName.main_page:
return pageBuilder.wrapWithNoAnim(MainPage());
case RouteName.demo_exception_page:
return pageBuilder.wrapWithNoAnim(wrapAwareWidget(RouteName.demo_exception_page, HandleExceptionPage()));
case RouteName.slide_out_page:
return pageBuilder.wrapWithSlideAnim(wrapAwareWidget(RouteName.slide_out_page, SlideOutPage()));
case RouteName.timer_page:
return pageBuilder.wrapWithNoAnim(TimerPage());

case RouteName.route_anim_page:
return pageBuilder.wrapWithNoAnim(RouteAnimationPage());
case RouteName.slide_page:
return pageBuilder.wrapWithSlideTopAnim(SlidePage());
case RouteName.fade_page:
return pageBuilder.wrapWithFadeAnim(FadePage());
case RouteName.scale_page:
return pageBuilder.wrapWithScaleAnim(ScalePage());

case RouteName.web_page:
return pageBuilder.wrapWithNoAnim(WebPageState(settings.arguments).generateWidget());
case RouteName.html_page:
return pageBuilder.wrapWithNoAnim(HtmlPage(settings.arguments));

case RouteName.editor_image_page:
///外层为动画
return pageBuilder.wrapWithSlideTopAnim(ImageEditorState(settings.arguments).generateWidget());
case RouteName.show_big_image:
return pageBuilder.wrapWithNoAnim(DetailImageWidget(settings.arguments));
// case RouteName.dialog_progress:
// return NoAnimRouteBuilder(LoadingProgress());
}
}

static RouteAwareWidget wrapAwareWidget(String name,Widget page){
assert(name != null, 'name must not null');
assert(page != null,'page child must not null');
return RouteAwareWidget(name, page);
}

}
/*
* 2020年9月9日16:02:34
*
* 路由改版后,下方全部废弃,你可以将它们删除
*
*
* */


//class RouteName{
//
// static const String demo_page = "demo_page";
// static const String demo_exception_page = "demo_exception_page";
// static const String main_page = 'main_page';
// static const String login_page = 'login_page';
// static const String pick_image_page = 'pick_image_page';
// static const String demo_other_page = 'demo_other_page';
// static const String scroll_page = 'scroll_page';
// static const String little_util_page = 'little_util_page';
// static const String slide_out_page = 'slide_out_page';
// static const String timer_page = 'timer_page';
// static const String permissions_page = 'permissions_page';
// static const String ffloat_page = 'ffloat_page';
// static const String cache_data_page = 'cache_data_page';
// static const String update_page = 'update_page';
//
// static const String route_anim_page = 'route_anim_page';
// static const String fade_page = 'fade_page';
// static const String scale_page = 'scale_page';
// static const String slide_page = 'slide_page';
//
// static const String local_i10l_page = 'local_i10l_page';
//
// static const String isolate_page = 'isolate_page';
//
//
// ///对指定图片进行裁剪、并返回对应路径
// static const String editor_image_page = "editor_image_page";
// ///显示大图
// static const String show_big_image = "show_big_image";
// ///web/html
// static const String web_page = 'web_page';
// static const String html_page = 'html_page';
//
// ///dialog式progress
// //static const String dialog_progress = 'dialog_progress';
//
//
//
//}
//
//
//
//class Router{
//
// static Route<dynamic> generateRoute(RouteSettings settings){
// switch(settings.name) {
// case RouteName.isolate_page:
// return pageBuilder.wrapWithNoAnim(IsolatePage());
// case RouteName.update_page:
// return pageBuilder.wrapWithNoAnim(UpdatePage());
// case RouteName.demo_page:
// ///注意这个方法 :wrapAwareWidget()
// ///这样包裹后,页面的pop和push就可以监听到,具体怎么使用可以根据你的业务需求来 eg:页面恢复、统计等
// ///代码参见 :RouteAwareWidget 和日志
// return pageBuilder.wrapWithNoAnim(wrapAwareWidget(RouteName.demo_page,DemoPage()));
// case RouteName.scroll_page:
// return pageBuilder.wrapWithNoAnim(ScrollPage());
// case RouteName.cache_data_page:
// return pageBuilder.wrapWithNoAnim(CacheDataPage());
// case RouteName.little_util_page:
// return pageBuilder.wrapWithNoAnim(LittleUtilPage());
// case RouteName.ffloat_page:
// return pageBuilder.wrapWithNoAnim(FFloatPage());
// case RouteName.permissions_page:
// return pageBuilder.wrapWithNoAnim(RequestPermissionsPage());
// case RouteName.demo_other_page:
// return pageBuilder.wrapWithNoAnim(OtherDemoPage());
// case RouteName.local_i10l_page:
// return pageBuilder.wrapWithNoAnim(LocalPage());
// case RouteName.login_page:
// return pageBuilder.wrapWithSlideTopAnim(LoginPage());
// case RouteName.pick_image_page:
// return pageBuilder.wrapWithNoAnim(PickImagePage());
// case RouteName.main_page:
// return pageBuilder.wrapWithNoAnim(MainPage());
// case RouteName.demo_exception_page:
// return pageBuilder.wrapWithNoAnim(wrapAwareWidget(RouteName.demo_exception_page, HandleExceptionPage()));
// case RouteName.slide_out_page:
// return pageBuilder.wrapWithSlideAnim(wrapAwareWidget(RouteName.slide_out_page, SlideOutPage()));
// case RouteName.timer_page:
// return pageBuilder.wrapWithNoAnim(TimerPage());
//
// case RouteName.route_anim_page:
// return pageBuilder.wrapWithNoAnim(RouteAnimationPage());
// case RouteName.slide_page:
// return pageBuilder.wrapWithSlideTopAnim(SlidePage());
// case RouteName.fade_page:
// return pageBuilder.wrapWithFadeAnim(FadePage());
// case RouteName.scale_page:
// return pageBuilder.wrapWithScaleAnim(ScalePage());
//
// case RouteName.web_page:
// return pageBuilder.wrapWithNoAnim(WebPageState(settings.arguments).generateWidget());
// case RouteName.html_page:
// return pageBuilder.wrapWithNoAnim(HtmlPage(settings.arguments));
//
// case RouteName.editor_image_page:
// ///外层为动画
// return pageBuilder.wrapWithSlideTopAnim(ImageEditorState(settings.arguments).generateWidget());
// case RouteName.show_big_image:
// return pageBuilder.wrapWithNoAnim(DetailImageWidget(settings.arguments));
//// case RouteName.dialog_progress:
//// return NoAnimRouteBuilder(LoadingProgress());
// }
// }
//
// static RouteAwareWidget wrapAwareWidget(String name,Widget page){
// assert(name != null, 'name must not null');
// assert(page != null,'page child must not null');
// return RouteAwareWidget(name, page);
// }
//
//}
5 changes: 5 additions & 0 deletions lib/base_framework/factory/page/page_animation_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import 'package:flutter_bedrock/base_framework/ui/anim/page_route_anim/slide_ani
final PageAnimationBuilder pageBuilder = PageAnimationBuilder.getInstance();

enum PageAnimation{
Fade,Scale,Slide,Non
}


class PageAnimationBuilder{

static PageAnimationBuilder singleton;
Expand Down
31 changes: 11 additions & 20 deletions lib/base_framework/ui/widget/progress_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bedrock/base_framework/widget_state/base_state.dart';

import 'package:flutter_bedrock/base_framework/widget_state/base_stateless_widget.dart';
import 'package:flutter_bedrock/base_framework/widget_state/widget_state.dart';

class CircleProgressWidget extends BaseStatelessWidget{
@override
Expand Down Expand Up @@ -57,33 +58,23 @@ class FullPageCircleProgressWidget extends BaseStatelessWidget{
//typedef LoadingCreate = void Function(DialogLoadingController controller);

class LoadingProgress extends StatefulWidget{

class LoadingProgressState extends WidgetState {

final Widget progress;
final Color bgColor;
//final LoadingCreate loadingCreate;
final DialogLoadingController controller;

const LoadingProgress({Key key, this.progress,
this.bgColor,@required this.controller })
: super(key: key);


@override
State<StatefulWidget> createState() {
return LoadingProgressState();
}

}

class LoadingProgressState extends BaseState<LoadingProgress> {
LoadingProgressState(this.progress, this.bgColor, this.controller);


@override
void initState() {
super.initState();

widget.controller.addListener(() {
if(widget.controller.isShow){
controller.addListener(() {
if(controller.isShow){
//todo
}else{
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
Expand All @@ -95,8 +86,8 @@ class LoadingProgressState extends BaseState<LoadingProgress> {

@override
void dispose() {
widget.controller.isShow = false;
widget.controller?.dispose();
controller.isShow = false;
controller?.dispose();
super.dispose();
}

Expand All @@ -106,10 +97,10 @@ class LoadingProgressState extends BaseState<LoadingProgress> {
final size = MediaQuery.of(context).size;

return Container(
color: widget.bgColor??Color.fromRGBO(34, 34, 34, 0.3),
color: bgColor??Color.fromRGBO(34, 34, 34, 0.3),
width: size.width,height: size.height,
alignment: Alignment.center,
child:widget.progress?? CircularProgressIndicator(),
child:progress?? CircularProgressIndicator(),
);
}
}
Expand Down
Loading

0 comments on commit 1fb8188

Please sign in to comment.