Thứ Tư, 10 tháng 6, 2020

How to set timeout when connect api in flutter

try {
  final request = await client.get(...);
  final response = await request.close()
    .timeout(const Duration(seconds: 2));
  // rest of the code
  ...
} on TimeoutException catch (_) {
  // A timeout occurred.
} on SocketException catch (_) {
  // Other exception
}

Thứ Ba, 9 tháng 6, 2020

How to Get/set in flutter

class Foo {
  String bar; // normal field (getter/setter)
  final String baz; // read-only (getter)

  int _weight;
  set weight(int value) {
    assert(weight >= 0);
    _weight = value;
  }
  int get weight => _weight
}

Thứ Hai, 8 tháng 6, 2020

// get time current
var today = new DateTime.now();
// add time var fiftyDaysFromNow = today.add(new Duration(days: 50));
// get timezome
var timezoneOffset = now.timeZoneOffset;

Thứ Năm, 4 tháng 6, 2020

Fomat number in flutter

final formatter = new NumberFormat("#,###");
new Text(formatter.format(1234)), // formatted number will be: 1,234

Thứ Tư, 27 tháng 11, 2019

Upload anh bang POST in flutter

static dynamic upImage(File imageFile) async {
  var stream = new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));  var length = await imageFile.length();  final String token = await constants.getToken();  var uri = Uri.parse(apiupload);
  Map<String, String> headers = {
    'se-client': "api",    'se-api-key': "f50949f7a35a3b0d46b08abd20bead1d:hd2OQtdb5Z9SCx5OAF7iKi97G8PsBJbX9YjIbYVHufDo4nVCycsJHvmPoXuRfVgv",    'se-viewer-token': token
  };  Map<String, String> body = {
    'typeId': 'image',    'productId': '@SE/Media',  };  var multipartFile = new http.MultipartFile('file', stream, length,filename: basename( imageFile.path));
  var request = new http.MultipartRequest("POST", uri);  request.headers.addAll(headers);  request.fields.addAll(body);  request.files.add(multipartFile);
  var response = await request.send();  return  await response.stream.bytesToString();}

Thứ Ba, 19 tháng 11, 2019

Nhìu định dạng chữ trong cùng 1 dòng in flutter

Text.rich(
  TextSpan(
    text: 'Hello ',
    style: TextStyle(fontSize: 50),
    children: <TextSpan>[
      TextSpan(
          text: 'world',
          style: TextStyle(
            decoration: TextDecoration.underline,
          )),
      // can add more TextSpans here...
    ],
  ),
)

Container full man hinh in flutter

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Container as a layout')),
body: Container(
height: double.infinity,
width: double.infinity,
color: Colors.yellowAccent,
child: Text("Hi"),
),
);
}

How to reload app in flutter

  Phoenix . rebirth (context);