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,30 +58,20 @@ 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();
} }
class _ASScaffoldState extends State<ASScaffold> { Widget get _appBar {
@override if (title == null && appBar == null && appBarBottom == null) return null;
Widget build(BuildContext context) { return appBar ??
return Scaffold(
key: widget.key,
endDrawer: widget.endDrawer,
backgroundColor: widget.backgroundColor,
bottomNavigationBar: widget.bottomNavigationBar,
floatingActionButton: widget.floatingActionButton,
appBar: widget.title == null &&
widget.appBar == null &&
widget.appBarBottom == null
? null
: widget.appBar ??
AppBar( AppBar(
brightness: Brightness.light, brightness: Brightness.light,
backgroundColor: kForegroundColor, backgroundColor: kForegroundColor,
elevation: 0, elevation: 0,
leading: widget.leading ?? ASBackButton(), leading: leading ?? ASBackButton(),
actions: widget.actions ?? [], actions: actions ?? [],
centerTitle: true, centerTitle: true,
title: DefaultTextStyle( title: DefaultTextStyle(
style: TextStyle( style: TextStyle(
@ -89,17 +79,26 @@ class _ASScaffoldState extends State<ASScaffold> {
fontSize: 18.sp, fontSize: 18.sp,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
child: widget.title is String child: _title,
? Text(widget.title)
: widget.title ?? SizedBox(),
), ),
bottom: widget.appBarBottom ?? bottom: appBarBottom ??
PreferredSize( PreferredSize(
child: SizedBox(), child: SizedBox(),
preferredSize: Size.fromHeight(0), preferredSize: Size.fromHeight(0),
), ),
), );
body: widget.body, }
@override
Widget build(BuildContext context) {
return Scaffold(
key: key,
endDrawer: endDrawer,
backgroundColor: backgroundColor,
bottomNavigationBar: bottomNavigationBar,
floatingActionButton: floatingActionButton,
appBar: _appBar,
body: body,
); );
} }
} }

Loading…
Cancel
Save