rrousselGit / functional_widget

A code generator to write widgets as function without loosing the benefits of classes.
597 stars 46 forks source link

error: The getter '_ticketNumber' isn't defined for the class 'FunctionalWidget'. #52

Closed pishguy closed 5 years ago

pishguy commented 5 years ago
...
import 'package:provider/provider.dart';
import 'package:functional_widget_annotation/functional_widget_annotation.dart';

part 'activity_show_ticket_replies.g.dart';

class ActivityShowTicketReplies extends StatefulWidget {
  final int ticketNumber;

  ActivityShowTicketReplies({@required this.ticketNumber});

  @override
  State<StatefulWidget> createState() => ActivityShowTicketRepliesState();
}

class ActivityShowTicketRepliesState extends State<ActivityShowTicketReplies> {
  /* GETTING THIS ERROR ON THIS LINE OF CODE */
  int get _ticketNumber => widget.ticketNumber;

  @override
  Widget build(BuildContext context) {
    return ScopedModel(
      ...
    );
  }
}

@widget
Widget _loader(BuildContext context, String message) {
  return Center(
      child: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    crossAxisAlignment: CrossAxisAlignment.center,
    children: <Widget>[
      ColorLoader3(
        radius: 25.0,
        dotRadius: 5.0,
      ),
      Padding(
        padding: const EdgeInsets.all(3.0),
        child: Text(
          Strings.pleaseWait,
          style: AppTheme(context).caption().copyWith(color: Colors.red[900]),
        ),
      ),
    ],
  ));
}
rrousselGit commented 5 years ago
import 'package:functional_widget_annotation/functional_widget_annotation.dart' as fn;

@fn.widget
Widget foo() {}

or:

import 'package:functional_widget_annotation/functional_widget_annotation.dart' show swidget;

@swidget
Widget foo() {}
hmayer00 commented 5 years ago

@rrousselGit Thanks, that fixed the same problem for me. Just curious, why is that necessary in this case? Is that true whenever the context is a StatefulWidget? And now I'm wondering whether I should just always use @fn.widget, or if there's a downside other than the extra characters?