0

if condition when post.text == 1 i setup Widget named exteranews

  Widget exteranews(BuildContext context) {
    double siz11 = 15.0 * MediaQuery.of(context).size.width / 414.0;

      }

how to use if with that Container

 Container(
                                   if (checkothers)   child: exteranews(context),
                                ),

i set String checkothers = post.text; i read i have to setup Widget to use run exteranews() but how to use if condition with it

Mikel Tawfik
  • 658
  • 3
  • 9
  • 23
  • Possible duplicate of [How to use conditional statement within child attribute of a Flutter Widget (Center Widget)](https://stackoverflow.com/questions/49713189/how-to-use-conditional-statement-within-child-attribute-of-a-flutter-widget-cen) – Mazin Ibrahim Aug 25 '19 at 13:54

1 Answers1

1
  1. You may use ? syntax
  2. please make sure to put Container() so it will display nothing its easier to image Container() equals to <div></div> in html
Widget extraNews(BuildContext context) {
  double siz11 = 15.0 * MediaQuery.of(context).size.width / 414.0;
  return Container();
}

class BaseScreen extends StatelessWidget {
  ///
  @override
  Widget build(BuildContext context) {
    return Container(
      child: checkothers == true ? extraNews(context) : Container(),
    );
  }
}
ejabu
  • 2,998
  • 23
  • 31