Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Follow publication

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

Shirsh Shukla
Nerd For Tech
Published in
9 min readJan 22, 2023

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) {
//...
}
}

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Shirsh Shukla
Shirsh Shukla

Written by Shirsh Shukla

SDE at Reliance Jio | Mobile Application Developer | Speaker | Technical Writer | community member at Stack Overflow | Organizer @FlutterIndore

No responses yet

Write a response