text
stringlengths 1
474
|
|---|
import 'package:http/http.dart' as http;
|
void main() {
|
runApp(const SampleApp());
|
}
|
class SampleApp extends StatelessWidget {
|
const SampleApp({super.key});
|
@override
|
Widget build(BuildContext context) {
|
return const MaterialApp(
|
title: 'Sample App',
|
home: SampleAppPage(),
|
);
|
}
|
}
|
class SampleAppPage extends StatefulWidget {
|
const SampleAppPage({super.key});
|
@override
|
State<SampleAppPage> createState() => _SampleAppPageState();
|
}
|
class _SampleAppPageState extends State<SampleAppPage> {
|
List<Map<String, dynamic>> data = <Map<String, dynamic>>[];
|
@override
|
void initState() {
|
super.initState();
|
loadData();
|
}
|
bool get showLoadingDialog => data.isEmpty;
|
Future<void> loadData() async {
|
final Uri dataURL = Uri.parse('https://jsonplaceholder.typicode.com/posts');
|
final http.Response response = await http.get(dataURL);
|
setState(() {
|
data = jsonDecode(response.body);
|
});
|
}
|
Widget getBody() {
|
if (showLoadingDialog) {
|
return getProgressDialog();
|
}
|
return getListView();
|
}
|
Widget getProgressDialog() {
|
return const Center(child: CircularProgressIndicator());
|
}
|
ListView getListView() {
|
return ListView.builder(
|
itemCount: data.length,
|
itemBuilder: (context, index) {
|
return getRow(index);
|
},
|
);
|
}
|
Widget getRow(int i) {
|
return Padding(
|
padding: const EdgeInsets.all(10),
|
child: Text("Row ${data[i]["title"]}"),
|
);
|
}
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
appBar: AppBar(
|
title: const Text('Sample App'),
|
),
|
body: getBody(),
|
);
|
}
|
}<code_end>
|
<topic_end>
|
<topic_start>Flutter for React Native developers
|
This document is for React Native (RN) developers looking to apply their
|
existing RN knowledge to build mobile apps with Flutter. If you understand
|
the fundamentals of the RN framework then you can use this document as a
|
way to get started learning Flutter development.This document can be used as a cookbook by jumping around and finding
|
questions that are most relevant to your needs.<topic_end>
|
<topic_start>
|
Introduction to Dart for JavaScript Developers (ES6)
|
Like React Native, Flutter uses reactive-style views. However, while RN
|
transpiles to native widgets, Flutter compiles all the way to native code.
|
Flutter controls each pixel on the screen, which avoids performance problems
|
caused by the need for a JavaScript bridge.Dart is an easy language to learn and offers the following features:A few examples of the differences between JavaScript and Dart are described
|
below.<topic_end>
|
<topic_start>
|
Entry point
|
JavaScript doesn’t have a pre-defined entry
|
function—you define the entry point.In Dart, every app must have a top-level main() function that serves as the
|
entry point to the app.
|
<code_start>/// Dart
|
void main() {}<code_end>
|
Try it out in DartPad.<topic_end>
|
<topic_start>
|
Printing to the console
|
To print to the console in Dart, use print().
|
<code_start>/// Dart
|
print('Hello world!');<code_end>
|
Try it out in DartPad.<topic_end>
|
<topic_start>
|
Variables
|
Dart is type safe—it uses a combination of static type checking
|
and runtime checks to ensure that a variable’s value always matches
|
the variable’s static type. Although types are mandatory,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.