Search code examples
flutterdartwidget

Separate widgets in other files flutter


I want to make my code neater but I have a problem when I separate widgets that I use often in 1 file

here is it my main widget

import 'package:a_tiket/Helpers/widget_helper.dart';
class LoginPage extends StatefulWidget {    
  @override
  _LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {

  bool _isLoading = false;
  var _message = '';
  var _hasError = false;

  @override
  Widget build(BuildContext context) {
    return
      _isLoading ?
      _loadingWidget(context)
          :
      Scaffold(
          body: SingleChildScrollView(
              child: Container(
                    ),
                  ],
                ),
              )
          )
      )
    ;
  }
}

this is my widget_helper.dart

Widget _loadingWidget (BuildContext context){
  return Scaffold(
    body: Center(
      child: CircularProgressIndicator(
        backgroundColor: ACCENT_COLOR,
        valueColor: new AlwaysStoppedAnimation<Color>(PRIMARY_COLOR),
      ),
    ),
  );
}

the problem is i got some error. i have add import for widget_helper but still get error

lib/Pages/loginPage.dart:193:7: Error: The method '_loadingWidget' isn't defined for the class '_LoginPageState'.

what should i do? i just want to make the code neater


Solution

  • please remove underline
    change from

    _loadingWidget(context)
    

    to

    loadingWidget(context)