Building a Flutter app? Avoid these common mistakes for a seamless experience.

Effortlessly build a Flutter app by avoiding these common mistakes. A smooth experience awaits.

Future<void> _sendNetworkRequest() async {
try {
var response = await http.get('https://example.com/data');
if (response.statusCode != 200) {
throw Exception('Error: Could not connect to server');
}
// process response
} catch (e) {
print(e);
}
}
Future<void> _sendNetworkRequest() async {
final response = await http.get('https://example.com/data')
.catchError((error) {
print(error);
return null;
})
.then((response) {
if (response.statusCode != 200) {
throw Exception('Error: Could not connect to server');
}
// process response
});
}
OrientationBuilder(
builder: (BuildContext context, Orientation orientation) {
return GridView.count(
crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
children: List.generate(100, (index) {
return Center(
child: Text(
'Item $index',
style: Theme.of(context).textTheme.headline,
),
);
}),
);
},
);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
ScreenUtil.init(context, width: 1080, height: 1920, allowFontScaling: true);
return Scaffold(
body: Column(
children: <Widget>[
SizedBox(
height: ScreenUtil().setHeight(200),
width: ScreenUtil().setWidth(1080),
child: Image.asset('assets/images/bgImage.png'),
),
],
),
);
}
}
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SettingsPage()),
);
MaterialApp(
routes: {
'/': (context) => HomePage(),
'/settings': (context) => SettingsPage(),
},
);
Navigator.pushNamed(context, '/settings');
Navigator.pushNamed(context, '/settings', arguments: 'data');
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
NetworkClient client = NetworkClient();
//...
}
}
class HomePage extends StatelessWidget {
final NetworkClient client;

HomePage({required this.client});

@override
Widget build(BuildContext context) {
//...
}
}

--

--

Mobile Application Developer | GDG Speaker | Technical Blogger at medium | community member at StackOverflow | Organizer @FlutterIndore

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shirsh Shukla

Mobile Application Developer | GDG Speaker | Technical Blogger at medium | community member at StackOverflow | Organizer @FlutterIndore