refactor: linting de widgets de layout y utilidades

Ajustes de estilo/linting en los helpers centered* de layout,
appIntroPage, roundedButton, secretLoader y utils (refactor pendiente).
This commit is contained in:
vjrj 2026-07-12 23:26:43 +02:00
parent 9b0fe987f8
commit 51fe8c6431
15 changed files with 141 additions and 126 deletions

View file

@ -11,7 +11,7 @@ class AppIntroItem {
final String title; final String title;
final String subTitle; final String subTitle;
AppIntroItem({this.icon, this.title, this.subTitle = ''}); AppIntroItem({required this.icon, required this.title, this.subTitle = ''});
// 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec vitae eros. Nunc sit amet neque. Ut id dui. Integer viverra feugiat sem. Morbi aliquam turpis rhoncus sapien volutpat condimentum.'}); // 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec vitae eros. Nunc sit amet neque. Ut id dui. Integer viverra feugiat sem. Morbi aliquam turpis rhoncus sapien volutpat condimentum.'});
} }
@ -23,83 +23,86 @@ abstract class AppIntroPage extends StatelessWidget {
final ListItems items; final ListItems items;
final OnIntroFinish onIntroFinish; final OnIntroFinish onIntroFinish;
const AppIntroPage({Key key, this.items, this.onIntroFinish}) const AppIntroPage(
{Key? key, required this.items, required this.onIntroFinish})
: super(key: key); : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return Scaffold(
// appBar: new AppBar(), // appBar: AppBar(),
body: new DefaultTabController( body: DefaultTabController(
length: items(context).length, length: items(context).length,
child: new _AppIntroPageSelector(items: items, onFinish: onIntroFinish), child: _AppIntroPageSelector(items: items, onFinish: onIntroFinish),
), ),
); );
} }
} }
class _AppIntroPageSelector extends StatelessWidget { class _AppIntroPageSelector extends StatelessWidget {
const _AppIntroPageSelector({this.items, this.onFinish}); const _AppIntroPageSelector({required this.items, required this.onFinish});
final ListItems items; final ListItems items;
final OnIntroFinish onFinish; final OnIntroFinish onFinish;
void _handleArrowButtonPress(BuildContext context, int delta) { void _handleArrowButtonPress(BuildContext context, int delta) {
final TabController controller = DefaultTabController.of(context); final TabController controller = DefaultTabController.of(context)!;
if (!controller.indexIsChanging) if (!controller.indexIsChanging)
controller controller.animateTo(
.animateTo((controller.index + delta).clamp(0, items(context).length - 1)); (controller.index + delta).clamp(0, items(context).length - 1));
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final TabController controller = DefaultTabController.of(context); final TabController controller = DefaultTabController.of(context)!;
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final Color color = theme.accentColor; final Color color = theme.colorScheme.secondary;
final TextStyle titleStyle = final TextStyle titleStyle =
theme.textTheme.headline.copyWith(color: color); (theme.textTheme.headlineSmall ?? const TextStyle())
.copyWith(color: color);
final TextStyle subTitleStyle = final TextStyle subTitleStyle =
theme.textTheme.subhead; //.copyWith(color: color); theme.textTheme.titleMedium ?? const TextStyle();
// final TextStyle descriptionStyle = theme.textTheme.subhead; // final TextStyle descriptionStyle = theme.textTheme.subhead;
return new SafeArea( return SafeArea(
top: true, top: true,
bottom: false, bottom: false,
child: new Column( child: Column(
children: <Widget>[ children: <Widget>[
new Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ Row(mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[
new IconButton( IconButton(
onPressed: () { onPressed: () {
onFinish(context); onFinish(context);
}, },
icon: new Icon(Icons.close, size: 30.0, color: Colors.black38)), icon:
const Icon(Icons.close, size: 30.0, color: Colors.black38)),
]), ]),
new Expanded( Expanded(child: OrientationBuilder(builder: (context, orientation) {
child: new OrientationBuilder(builder: (context, orientation) { return IconTheme(
return new IconTheme( data: IconThemeData(
data: new IconThemeData(
size: orientation == Orientation.portrait ? 200.0 : 100.0, size: orientation == Orientation.portrait ? 200.0 : 100.0,
color: color, color: color,
), ),
child: new TabBarView( child: TabBarView(
children: items(context).map((AppIntroItem item) { children: items(context).map((AppIntroItem item) {
return new Container( return Container(
padding: const EdgeInsets.all(12.0), padding: const EdgeInsets.all(12.0),
child: new Center( child: Center(
child: new CenteredSpaceEvenlyColumn(children: <Widget>[ child: CenteredSpaceEvenlyColumn(children: <Widget>[
Icon( Icon(
item.icon, item.icon,
semanticLabel: item.title, semanticLabel: item.title,
), ),
new Padding( Padding(
padding: new EdgeInsets.only(left: 16.0, right: 16.0), padding:
child: new CenteredColumn(children: <Widget>[ const EdgeInsets.only(left: 16.0, right: 16.0),
new Text( child: CenteredColumn(children: <Widget>[
Text(
item.title, item.title,
style: titleStyle, style: titleStyle,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
new SizedBox(height: 20.0), const SizedBox(height: 20.0),
new Text( Text(
item.subTitle, item.subTitle,
style: subTitleStyle, style: subTitleStyle,
textAlign: TextAlign.center, textAlign: TextAlign.center,
@ -111,19 +114,19 @@ class _AppIntroPageSelector extends StatelessWidget {
}).toList()), }).toList()),
); );
})), })),
new Container( Container(
margin: const EdgeInsets.only(top: 16.0), margin: const EdgeInsets.only(top: 16.0),
child: new Row( child: Row(
children: listWithoutNulls(<Widget>[ children: listWithoutNulls(<Widget>[
new IconButton( IconButton(
icon: const Icon(Icons.chevron_left), icon: const Icon(Icons.chevron_left),
color: color, color: color,
onPressed: () { onPressed: () {
_handleArrowButtonPress(context, -1); _handleArrowButtonPress(context, -1);
}, },
tooltip: 'Page back'), tooltip: 'Page back'),
new TabPageSelector(controller: controller), TabPageSelector(controller: controller),
new IconButton( IconButton(
icon: const Icon(Icons.chevron_right), icon: const Icon(Icons.chevron_right),
color: color, color: color,
onPressed: () { onPressed: () {

View file

@ -2,15 +2,15 @@ import 'package:flutter/material.dart';
abstract class AbstractCenteredColumn extends Column { abstract class AbstractCenteredColumn extends Column {
AbstractCenteredColumn({ AbstractCenteredColumn({
Key key, Key? key,
MainAxisAlignment mainAxisAlignment, MainAxisAlignment? mainAxisAlignment,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,
mainAxisAlignment: mainAxisAlignment, mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
textDirection: textDirection, textDirection: textDirection,

View file

@ -2,15 +2,15 @@ import 'package:flutter/material.dart';
abstract class AbstractCenteredRow extends Row { abstract class AbstractCenteredRow extends Row {
AbstractCenteredRow({ AbstractCenteredRow({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
mainAxisAlignment, mainAxisAlignment,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,
mainAxisAlignment: mainAxisAlignment, mainAxisAlignment: mainAxisAlignment ?? MainAxisAlignment.start,
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
textDirection: textDirection, textDirection: textDirection,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredColumn.dart';
class CenteredColumn extends AbstractCenteredColumn { class CenteredColumn extends AbstractCenteredColumn {
CenteredColumn({ CenteredColumn({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -4,10 +4,10 @@ import 'centeredRow.dart';
class CenteredMaxWidget extends CenteredColumn { class CenteredMaxWidget extends CenteredColumn {
CenteredMaxWidget({ CenteredMaxWidget({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: <Widget>[new CenteredRow(children: children)], children: <Widget>[new CenteredRow(children: children)],
key: key, key: key,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredRow.dart';
class CenteredRow extends AbstractCenteredRow { class CenteredRow extends AbstractCenteredRow {
CenteredRow({ CenteredRow({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredColumn.dart';
class CenteredSpaceAroundColumn extends AbstractCenteredColumn { class CenteredSpaceAroundColumn extends AbstractCenteredColumn {
CenteredSpaceAroundColumn({ CenteredSpaceAroundColumn({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredRow.dart';
class CenteredSpacedAroundRow extends AbstractCenteredRow { class CenteredSpacedAroundRow extends AbstractCenteredRow {
CenteredSpacedAroundRow({ CenteredSpacedAroundRow({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredColumn.dart';
class CenteredSpaceBetweenColumn extends AbstractCenteredColumn { class CenteredSpaceBetweenColumn extends AbstractCenteredColumn {
CenteredSpaceBetweenColumn({ CenteredSpaceBetweenColumn({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredRow.dart';
class CenteredSpacedBetweenRow extends AbstractCenteredRow { class CenteredSpacedBetweenRow extends AbstractCenteredRow {
CenteredSpacedBetweenRow({ CenteredSpacedBetweenRow({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredColumn.dart';
class CenteredSpaceEvenlyColumn extends AbstractCenteredColumn { class CenteredSpaceEvenlyColumn extends AbstractCenteredColumn {
CenteredSpaceEvenlyColumn({ CenteredSpaceEvenlyColumn({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -3,10 +3,10 @@ import 'abstractCenteredRow.dart';
class CenteredSpacedEvenlyRow extends AbstractCenteredRow { class CenteredSpacedEvenlyRow extends AbstractCenteredRow {
CenteredSpacedEvenlyRow({ CenteredSpacedEvenlyRow({
Key key, Key? key,
TextDirection textDirection, TextDirection? textDirection,
TextBaseline textBaseline, TextBaseline? textBaseline,
List<Widget> children: const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
key: key, key: key,

View file

@ -5,11 +5,11 @@ import 'package:flutter/services.dart' show rootBundle;
class SecretLoader { class SecretLoader {
final String secretPath; final String secretPath;
SecretLoader({this.secretPath}); SecretLoader({required this.secretPath});
Future<Map<String, dynamic>> load() { Future<Map<String, dynamic>> load() {
rootBundle.loadString(secretPath, cache: false); rootBundle.loadString(secretPath, cache: false);
return rootBundle.loadStructuredData<Map<String, dynamic>>(this.secretPath, return rootBundle.loadStructuredData<Map<String, dynamic>>(secretPath,
(jsonStr) async { (jsonStr) async {
return json.decode(jsonStr); return json.decode(jsonStr);
}); });

View file

@ -8,4 +8,4 @@ bool notNull(Object o) => o != null;
List<Widget> listWithoutNulls(List<Widget> children) => List<Widget> listWithoutNulls(List<Widget> children) =>
children.where(notNull).toList(); children.where(notNull).toList();
ellipse(String s,[ int end = 4]) => s != null ? s.substring(0, end) + '...' : null; ellipse(String s,[ int end = 4]) => s.substring(0, end) + '...';

View file

@ -1,56 +1,68 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class RoundedBtn extends StatelessWidget { class RoundedBtn extends StatelessWidget {
final btnRadius = new Radius.circular(90.0); static const btnRadius = Radius.circular(90.0);
final IconData icon; final IconData icon;
final String text; final String text;
final Color backColor; final Color backColor;
final Color fontColor; final Color fontColor;
final TextStyle textStyle; final TextStyle textStyle;
VoidCallback onPressed; final VoidCallback onPressed;
RoundedBtn( const RoundedBtn({
{@required this.icon, required this.icon,
@required this.text, required this.text,
@required this.onPressed, required this.onPressed,
@required this.backColor, required this.backColor,
this.textStyle = const TextStyle(fontSize: 20.0, color: Colors.white), this.textStyle = const TextStyle(fontSize: 20.0, color: Colors.white),
this.fontColor = Colors.white}); this.fontColor = Colors.white,
});
RoundedBtn.nav( factory RoundedBtn.nav({
{@required this.icon, required IconData icon,
@required this.text, required String text,
@required BuildContext context, required BuildContext context,
@required route, required String route,
@required this.backColor, required Color backColor,
this.textStyle = const TextStyle(fontSize: 20.0, color: Colors.white), TextStyle textStyle = const TextStyle(fontSize: 20.0, color: Colors.white),
this.fontColor = Colors.white}) { Color fontColor = Colors.white,
this.onPressed = () { }) {
Navigator.pushNamed(context, route); return RoundedBtn(
}; icon: icon,
text: text,
onPressed: () {
Navigator.pushNamed(context, route);
},
backColor: backColor,
textStyle: textStyle,
fontColor: fontColor,
);
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new SizedBox( return SizedBox(
child: new RaisedButton( child: ElevatedButton(
elevation: 1.0, onPressed: onPressed,
color: backColor, style: ElevatedButton.styleFrom(
child: new Padding( backgroundColor: backColor,
padding: const EdgeInsets.all(10.0), shape: RoundedRectangleBorder(
child: new Row( borderRadius: BorderRadius.all(btnRadius),
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Icon(icon, size: 32.0, color: fontColor),
new SizedBox(width: 10.0),
new Text(text, style: textStyle),
],
),
), ),
onPressed: onPressed, ),
shape: new RoundedRectangleBorder( child: Padding(
borderRadius: BorderRadius.all(btnRadius))), padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(icon, size: 32.0, color: fontColor),
const SizedBox(width: 10.0),
Text(text, style: textStyle),
],
),
),
),
); );
} }
} }