Flutter User Interface (UI)
Pemrograman Mobile 2
Muhamad Saad Nurul Ishlah, M.Comp.
Dept. Sistem Informasi & Dept. Ilmu Komputer, Universitas Pakuan
Responsif
Adaptif
Pendekatan:
Widget yang dapat digunakan:
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
if (mediaQuery.size.width > 1024) {
return LargeLayout();
}
if (mediaQuery.size.width > 332) {
return MediumLayout();
}
return SmallLayout();
}
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
if (mediaQuery.devicePixelRatio >= 2) {
return HighDefinitionVideo();
}
return LowDefinitionVideo();
}
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
return Padding(
padding: EdgeInsets.only(
top: mediaQuery.padding.top,
),
child: Child(),
);
}
@override
Widget build(BuildContext context) {
return SafeArea(
left: false,
right: false,
bottom: false,
child: Child(),
);
}
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
return Padding(
padding: EdgeInsets.only(
bottom: mediaQuery.viewInsets.bottom,
),
child: Child(),
);
}
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
return Image.asset(
mediaQuery.platformBrightness == Brightness.dark
? 'assets/background_dark.png'
: 'assets/background_light.png',
);
}
import 'dart:io';
import 'package:flutter/foundation.dart';
@override
Widget build(BuildContext context) {
if(kIsWeb || Platform.isMacOS || Platform.isLinux || Platform.isWindows) {
return DesktopLayout();
}
return MobileLayout();
}
@override
Widget build(BuildContext context) {
final locale = Localizations.localeOf(context);
return Image.asset('flag_${locale.countryCode}.png');
}
@override
Widget build(BuildContext context) {
final locale = Localizations.localeOf(context);
final formattedDate = DateFormat.yMMMMEEEEd(locale.toString());
return Text(formattedDate);
}
@override
Widget build(BuildContext context) {
final direction = Directionality.of(context);
return Image.asset('horizontal_illustration_${direction.value}.png');
}
@override
Widget build(BuildContext context) {
final direction = Directionality.of(context);
return Image.asset('horizontal_illustration_${direction.value}.png');
}