0% found this document useful (0 votes)
5 views3 pages

Flutter Revision Guide Clean

This document provides a comprehensive revision of Flutter, covering basics, widget types, common widgets, state management, navigation, forms, HTTP requests, async/await, local storage, widget lifecycle, themes, responsive layouts, CLI commands, useful packages, best practices, folder structure, and an example of pubspec.yaml. It includes code snippets and explanations for each topic. The content is aimed at helping developers quickly reference essential Flutter concepts and syntax.

Uploaded by

anshraut807
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Flutter Revision Guide Clean

This document provides a comprehensive revision of Flutter, covering basics, widget types, common widgets, state management, navigation, forms, HTTP requests, async/await, local storage, widget lifecycle, themes, responsive layouts, CLI commands, useful packages, best practices, folder structure, and an example of pubspec.yaml. It includes code snippets and explanations for each topic. The content is aimed at helping developers quickly reference essential Flutter concepts and syntax.

Uploaded by

anshraut807
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Flutter Complete Revision (With Common Syntax)

Flutter Quick Revision

FLUTTER COMPLETE REVISION (WITH COMMON SYNTAX)

1. Flutter Basics
void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(home: HomeScreen());
}
}

2. Widget Types
StatelessWidget:
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text('Hello');
}
}

StatefulWidget:
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
int counter = 0;
@override
Widget build(BuildContext context) {
return Text('$counter');
}
}

3. Common Widgets
Row(children: [Text('Left'), Text('Right')])
Column(children: [Text('Top'), Text('Bottom')])
Container(padding: EdgeInsets.all(10), color: Colors.blue, child: Text('Container'))

Text('Hello', style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold))

ElevatedButton(onPressed: () { print('Clicked'); }, child: Text('Click Me'))

4. State Management
setState:
Flutter Complete Revision (With Common Syntax)

int count = 0;
ElevatedButton(onPressed: () {
setState(() { count++; });
}, child: Text('Count: $count'))

Provider:
class Counter with ChangeNotifier {
int value = 0;
void increment() { value++; notifyListeners(); }
}
context.read<Counter>().increment();

5. Navigation & Routes


Navigator.push(context, MaterialPageRoute(builder: (context) => NextScreen()));
Navigator.pushNamed(context, '/about');

6. Forms & Input


final _formKey = GlobalKey<FormState>();
Form(
key: _formKey,
child: Column(children: [
TextFormField(validator: (value) => value == null || value.isEmpty ? 'Enter
something' : null),
ElevatedButton(onPressed: () {
if (_formKey.currentState!.validate()) {}
}, child: Text('Submit'))
]),
)

7. HTTP Request
import 'package:http/http.dart' as http;
import 'dart:convert';
Future<void> fetchData() async {
final response = await http.get(Uri.parse('https://api.example.com/data'));
if (response.statusCode == 200) {
var data = jsonDecode(response.body);
print(data);
}
}

8. Async/Await
Future<String> getData() async {
await Future.delayed(Duration(seconds: 1));
return 'Done';
}

9. Local Storage - Shared Preferences


SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('username', 'John');
String? user = prefs.getString('username');
Flutter Complete Revision (With Common Syntax)

10. Widget Lifecycle


initState(), dispose()

11. Themes
MaterialApp(theme: ThemeData(primarySwatch: Colors.blue, textTheme: TextTheme(bodyLarge:
TextStyle(fontSize: 18))))

12. Responsive Layout


MediaQuery.of(context).size.width
LayoutBuilder(builder: (context, constraints) {
return constraints.maxWidth > 600 ? WideLayout() : NarrowLayout();
});

13. Flutter CLI Commands


flutter doctor, flutter create, flutter run, flutter build apk, flutter pub get, flutter
upgrade

14. Useful Packages


provider, riverpod, http, dio, shared_preferences, hive, go_router

15. Best Practices


Use const, use SingleChildScrollView, split UI, use linter, keep business logic separate

16. Folder Structure


/lib, /screens, /widgets, /models, /services, /assets

17. pubspec.yaml Example


name: my_app
dependencies:
flutter:
sdk: flutter
http: ^0.14.0
provider: ^6.0.0
shared_preferences: ^2.0.0
assets:
- assets/images/

You might also like