I'm new in dart and I want to know what's the best implementation or the best practice between using a function or an object to do "simple" action
- Using a function
file: progress.dart
import 'package:flutter/material.dart';
Center buildProgressIndicator(BuildContext context) {
return Center(
child: new CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(Colors.green),
),
);
}```
file: home.dart
...
if (!snapshot.hasData) return buildProgressIndicator(context);
...
- Using an objet
file: progress.dart
import 'package:flutter/material.dart';
class CustomProgressIndicator extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: new CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(Colors.green),
),
);
}
}
file: home.dart
...
if (!snapshot.hasData) return CustomProgressIndicator();
...
In the example above, the 2 versions seem to work in the same way. Therefore, I'm a little bit confused to do the best implementation choice !