migrate scaffold from stateful to stateless

null_safety
小赖 4 years ago
parent 4adb66e863
commit 1ee38aece1

@ -14,7 +14,7 @@ import 'package:ansu_ui/buttons/as_back_button.dart';
///title , AppBar AppBarBottom `null`scaffoldAppBar ///title , AppBar AppBarBottom `null`scaffoldAppBar
/// ///
///AppBarBottomAppBarBottom ///AppBarBottomAppBarBottom
class ASScaffold extends StatefulWidget { class ASScaffold extends StatelessWidget {
///`String``Text` ///`String``Text`
final dynamic title; final dynamic title;
@ -58,48 +58,47 @@ class ASScaffold extends StatefulWidget {
this.floatingActionButton, this.floatingActionButton,
}) : super(key: key); }) : super(key: key);
@override Widget get _title {
_ASScaffoldState createState() => _ASScaffoldState(); if (title is String) return Text(title);
} return title ?? SizedBox();
}
Widget get _appBar {
if (title == null && appBar == null && appBarBottom == null) return null;
return appBar ??
AppBar(
brightness: Brightness.light,
backgroundColor: kForegroundColor,
elevation: 0,
leading: leading ?? ASBackButton(),
actions: actions ?? [],
centerTitle: true,
title: DefaultTextStyle(
style: TextStyle(
color: kTextColor,
fontSize: 18.sp,
fontWeight: FontWeight.bold,
),
child: _title,
),
bottom: appBarBottom ??
PreferredSize(
child: SizedBox(),
preferredSize: Size.fromHeight(0),
),
);
}
class _ASScaffoldState extends State<ASScaffold> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
key: widget.key, key: key,
endDrawer: widget.endDrawer, endDrawer: endDrawer,
backgroundColor: widget.backgroundColor, backgroundColor: backgroundColor,
bottomNavigationBar: widget.bottomNavigationBar, bottomNavigationBar: bottomNavigationBar,
floatingActionButton: widget.floatingActionButton, floatingActionButton: floatingActionButton,
appBar: widget.title == null && appBar: _appBar,
widget.appBar == null && body: body,
widget.appBarBottom == null
? null
: widget.appBar ??
AppBar(
brightness: Brightness.light,
backgroundColor: kForegroundColor,
elevation: 0,
leading: widget.leading ?? ASBackButton(),
actions: widget.actions ?? [],
centerTitle: true,
title: DefaultTextStyle(
style: TextStyle(
color: kTextColor,
fontSize: 18.sp,
fontWeight: FontWeight.bold,
),
child: widget.title is String
? Text(widget.title)
: widget.title ?? SizedBox(),
),
bottom: widget.appBarBottom ??
PreferredSize(
child: SizedBox(),
preferredSize: Size.fromHeight(0),
),
),
body: widget.body,
); );
} }
} }

Loading…
Cancel
Save