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
Using Flutter Outline: Use the Flutter Outline tool to split an app into widgets as shown below: Flutter Outline is present on the right-hand side as a hidden tab. After opening the tab we can see the Widget Tree of the current dart file. Right-click on the widget we want to extract -> click on Extract Widget.
Flutter Outline is present on the right-hand side as a hidden tab. After opening the tab we can see the Widget Tree of the current dart file. Right-click on the widget we want to extract -> click on Extract Widget. Give a name for the widget->Click Refactor. The widget will be extracted.
The first step is to open your flutter project and select the lib folder. 2. Now we would make another folder named ad modules inside the lib folder. We have to put all the files inside the lib folder in order to make the use. 3. As you can see in above screenshot there are 1 modules name folder, our main.dart file and textmsg.dart file.
Once you code an app of medium complexity, it becomes very important to think about the performance impact of your Flutter widgets. Thinking about app performance is about being a good app citizen. Not only the app will be smoother for the user, but also it will drain less battery.
please remove underline
change from
_loadingWidget(context)
to
loadingWidget(context)
There are a few issues with your code:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With