text
stringlengths 1
372
|
|---|
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 index) {
|
return padding(
|
padding: const EdgeInsets.all(10),
|
child: Text('Row ${data[index]['title']}'),
|
);
|
}
|
@override
|
widget build(BuildContext context) {
|
return scaffold(
|
appBar: AppBar(title: const Text('Sample app')),
|
body: getBody(),
|
);
|
}
|
}
|
<code_end>
|
<topic_end>
|
<topic_start>
|
project structure & resources
|
<topic_end>
|
<topic_start>
|
where do i store my image files?
|
Xamarin.Forms has no platform independent way of storing images,
|
you had to place images in the iOS xcasset folder,
|
or on android in the various drawable folders.
|
while android and iOS treat resources and assets as distinct items,
|
flutter apps have only assets.
|
all resources that would live in the
|
resources/drawable-* folders on android,
|
are placed in an assets’ folder for flutter.
|
flutter follows a simple density-based format like iOS.
|
assets might be 1.0x, 2.0x, 3.0x, or any other multiplier.
|
flutter doesn’t have dps but there are logical pixels,
|
which are basically the same as device-independent pixels.
|
flutter’s devicePixelRatio expresses the ratio
|
of physical pixels in a single logical pixel.
|
the equivalent to android’s density buckets are:
|
assets are located in any arbitrary folder—
|
flutter has no predefined folder structure.
|
you declare the assets (with location)
|
in the pubspec.yaml file, and flutter picks them up.
|
to add a new image asset called my_icon.png to our flutter project,
|
for example, and deciding that it should live in a folder we
|
arbitrarily called images, you would put the base image (1.0x)
|
in the images folder, and all the other variants in sub-folders
|
called with the appropriate ratio multiplier:
|
next, you’ll need to declare these images in your pubspec.yaml file:
|
you can directly access your images in an image.asset widget:
|
<code_start>
|
@override
|
widget build(BuildContext context) {
|
return image.asset('images/my_icon.png');
|
}
|
<code_end>
|
or using AssetImage:
|
<code_start>
|
@override
|
widget build(BuildContext context) {
|
return const image(
|
image: AssetImage('images/my_image.png'),
|
);
|
}
|
<code_end>
|
more detailed information can be found in adding assets and images.
|
<topic_end>
|
<topic_start>
|
where do i store strings? how do i handle localization?
|
unlike .net which has resx files,
|
flutter doesn’t currently have a dedicated system for handling strings.
|
at the moment, the best practice is to declare your copy text
|
in a class as static fields and access them from there. for example:
|
<code_start>
|
class strings {
|
static const string welcomeMessage = 'welcome to flutter';
|
}
|
<code_end>
|
you can access your strings as such:
|
<code_start>
|
Text(Strings.welcomeMessage);
|
<code_end>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.