flutter_foldable_kit ๐Ÿ“ฑ๐Ÿ“–

pub package license version


๐Ÿ‡ฎ๐Ÿ‡ฉ Bahasa Indonesia | ๐Ÿ‡ฌ๐Ÿ‡ง English


๐Ÿ‡ฎ๐Ÿ‡ฉ Deskripsi (Indonesian)

Library Flutter siap pakai (plug-and-play) untuk mengembangkan aplikasi modern pada perangkat Foldable (Samsung Galaxy Z Fold, Google Pixel Fold), Flip (Galaxy Z Flip, Motorola Razr), Dual-Screen (Surface Duo), dan Tablet.

Tidak perlu lagi menghitung bounding box DisplayFeature atau menulis logika MediaQuery yang rumit secara manual. Cukup panggil widget dari library ini!

๐Ÿ‡ฌ๐Ÿ‡ง Description (English)

A plug-and-play Flutter library for building modern apps on Foldable (Samsung Galaxy Z Fold, Google Pixel Fold), Flip (Galaxy Z Flip, Motorola Razr), Dual-Screen (Surface Duo), and Tablet devices.

No more manually calculating DisplayFeature bounding boxes or writing complex MediaQuery logic. Just call the widgets from this library!


๐ŸŒŸ Fitur Utama / Key Features

Widget ๐Ÿ‡ฎ๐Ÿ‡ฉ Deskripsi ๐Ÿ‡ฌ๐Ÿ‡ง Description
FoldableSplitView Layout dua panel otomatis di kedua sisi lipatan fisik. Fallback ke single pane pada layar kecil. Automatic two-pane layout aligned to the physical hinge. Falls back to single pane on small screens.
OnHingeChange Listener reaktif saat engsel ditekuk atau dibuka (Book Mode, Tabletop/Flex Mode, Flat). Reactive listener when the hinge is bent or straightened (Book Mode, Tabletop/Flex Mode, Flat).
FoldableTabView Tab navigation cerdas: Bottom Bar saat tertutup, Navigation Rail saat terbuka, Flex Control saat tabletop. Smart tab navigation: Bottom Bar when folded, Navigation Rail when opened, Flex Control in tabletop mode.
FoldableNavigationSplitView Pola Master-Detail: dua kolom di layar terbuka, stack push/pop di layar kecil. Master-Detail pattern: two-column on wide screens, push/pop stack on compact screens.
BuildContext Extensions context.isFoldable, context.isTabletop, context.isBookMode, context.hingeBounds, dll. context.isFoldable, context.isTabletop, context.isBookMode, context.hingeBounds, etc.

๐Ÿš€ Instalasi / Installation

๐Ÿ‡ฎ๐Ÿ‡ฉ Tambahkan ke pubspec.yaml Anda:

๐Ÿ‡ฌ๐Ÿ‡ง Add to your pubspec.yaml:

dependencies:
  flutter_foldable_kit: ^1.1.0

๐Ÿ‡ฎ๐Ÿ‡ฉ Lalu impor di file Dart Anda:

๐Ÿ‡ฌ๐Ÿ‡ง Then import in your Dart file:

import 'package:flutter_foldable_kit/flutter_foldable_kit.dart';

๐Ÿ“– Panduan Penggunaan / Usage Guide

1. BuildContext Extensions

๐Ÿ‡ฎ๐Ÿ‡ฉ Dapatkan status lipatan di widget mana saja tanpa boilerplate:
๐Ÿ‡ฌ๐Ÿ‡ง Access fold state anywhere in your widget tree without boilerplate:

Widget build(BuildContext context) {
  if (context.isTabletop) {
    // ๐Ÿ‡ฎ๐Ÿ‡ฉ Mode laptop/flex (Z Flip atau Z Fold ditekuk horizontal di atas meja)
    // ๐Ÿ‡ฌ๐Ÿ‡ง Flex/tabletop mode (Z Flip or Z Fold bent horizontally on a table)
    return buildTabletopLayout();
  } else if (context.isBookMode) {
    // ๐Ÿ‡ฎ๐Ÿ‡ฉ Mode buku (Z Fold dibuka vertikal)
    // ๐Ÿ‡ฌ๐Ÿ‡ง Book mode (Z Fold opened vertically)
    return buildBookModeLayout();
  }

  return buildStandardLayout();
}

๐Ÿ‡ฎ๐Ÿ‡ฉ Tersedia juga / ๐Ÿ‡ฌ๐Ÿ‡ง Also available:

  • context.isFoldable / context.hasHinge โ€” ๐Ÿ‡ฎ๐Ÿ‡ฉ Apakah perangkat memiliki lipatan aktif / ๐Ÿ‡ฌ๐Ÿ‡ง Whether device has an active fold.
  • context.devicePosture โ€” DevicePosture.flat, DevicePosture.halfOpened, DevicePosture.folded
  • context.hingeBounds โ€” ๐Ÿ‡ฎ๐Ÿ‡ฉ Bounding box area engsel (Rect) / ๐Ÿ‡ฌ๐Ÿ‡ง Hinge area bounding box (Rect).
  • context.hingeThickness โ€” ๐Ÿ‡ฎ๐Ÿ‡ฉ Ketebalan lipatan fisik dalam pixel logika / ๐Ÿ‡ฌ๐Ÿ‡ง Physical hinge thickness in logical pixels.

2. FoldableSplitView

๐Ÿ‡ฎ๐Ÿ‡ฉ Membagi tampilan ke dua sisi engsel fisik secara presisi:
๐Ÿ‡ฌ๐Ÿ‡ง Splits the view across the physical hinge precisely:

FoldableSplitView(
  startPane: ListView(
    children: [
      // ๐Ÿ‡ฎ๐Ÿ‡ฉ Daftar Produk / ๐Ÿ‡ฌ๐Ÿ‡ง Product List
      Text('Items'),
    ],
  ),
  endPane: Center(
    // ๐Ÿ‡ฎ๐Ÿ‡ฉ Detail Produk / ๐Ÿ‡ฌ๐Ÿ‡ง Product Detail
    child: Text('Detail'),
  ),
  // ๐Ÿ‡ฎ๐Ÿ‡ฉ Rasio saat di layar tablet tanpa engsel (default: 0.4)
  // ๐Ÿ‡ฌ๐Ÿ‡ง Ratio on tablet screen without hinge (default: 0.4)
  ratio: 0.4,
)

3. OnHingeChange

๐Ÿ‡ฎ๐Ÿ‡ฉ Merespon secara instan saat pengguna menekuk atau meluruskan ponsel:
๐Ÿ‡ฌ๐Ÿ‡ง Responds instantly when the user bends or straightens the phone:

OnHingeChange(
  onTabletopEnter: () {
    // ๐Ÿ‡ฎ๐Ÿ‡ฉ Ponsel diletakkan di meja (Tabletop Mode)!
    // ๐Ÿ‡ฌ๐Ÿ‡ง Phone placed on table (Tabletop Mode)!
    print('Entered Tabletop Mode');
  },
  onTabletopExit: () {
    print('Exited Tabletop Mode');
  },
  onPostureChange: (posture) {
    // ๐Ÿ‡ฎ๐Ÿ‡ฉ Postur berubah / ๐Ÿ‡ฌ๐Ÿ‡ง Posture changed
    print('Posture: $posture');
  },
  child: MyMainScreen(),
)

4. FoldableTabView

๐Ÿ‡ฎ๐Ÿ‡ฉ Secara cerdas berganti antara Bottom Navigation Bar, Navigation Rail, dan Flex Mode:
๐Ÿ‡ฌ๐Ÿ‡ง Intelligently switches between Bottom Navigation Bar, Navigation Rail, and Flex Mode:

FoldableTabView(
  tabs: [
    FoldableTabItem(
      label: 'Home',
      icon: Icon(Icons.home_outlined),
      activeIcon: Icon(Icons.home),
      content: HomeView(),
    ),
    FoldableTabItem(
      label: 'Chat',
      icon: Icon(Icons.chat_bubble_outline),
      activeIcon: Icon(Icons.chat_bubble),
      content: ChatView(),
    ),
    FoldableTabItem(
      label: 'Profile / Profil',
      icon: Icon(Icons.person_outline),
      activeIcon: Icon(Icons.person),
      content: ProfileView(),
    ),
  ],
)

5. FoldableNavigationSplitView

๐Ÿ‡ฎ๐Ÿ‡ฉ Menampilkan daftar dan detail berdampingan di layar besar, otomatis menjadi stack push/pop di layar kecil:
๐Ÿ‡ฌ๐Ÿ‡ง Shows list and detail side-by-side on large screens, automatically becomes push/pop stack on small screens:

FoldableNavigationSplitView<EmailItem>(
  initialItem: sampleEmails.first,
  masterBuilder: (context, selectedItem, onSelect) {
    return ListView.builder(
      itemCount: emails.length,
      itemBuilder: (context, index) {
        final email = emails[index];
        return ListTile(
          selected: selectedItem?.id == email.id,
          title: Text(email.sender),
          subtitle: Text(email.subject),
          onTap: () => onSelect(email),
        );
      },
    );
  },
  detailBuilder: (context, item, isSplitMode) {
    return Scaffold(
      appBar: AppBar(
        title: Text(item.subject),
        // ๐Ÿ‡ฎ๐Ÿ‡ฉ Tombol Back otomatis hanya muncul jika berada di layar single
        // ๐Ÿ‡ฌ๐Ÿ‡ง Back button automatically shown only on single-screen mode
        leading: isSplitMode ? null : const BackButton(),
      ),
      body: EmailDetailView(email: item),
    );
  },
)

๐Ÿงช Pengujian / Testing

๐Ÿ‡ฎ๐Ÿ‡ฉ Jalankan test suite bawaan:
๐Ÿ‡ฌ๐Ÿ‡ง Run the built-in test suite:

flutter test

๐Ÿ‡ฎ๐Ÿ‡ฉ Semua komponen dilengkapi dengan unit test dan widget test untuk memastikan integritas layout di berbagai resolusi layar dan status engsel.

๐Ÿ‡ฌ๐Ÿ‡ง All components come with unit tests and widget tests to ensure layout integrity across various screen resolutions and hinge states.


๐Ÿ“„ Lisensi / License

๐Ÿ‡ฎ๐Ÿ‡ฉ Dilisensikan di bawah MIT License.
๐Ÿ‡ฌ๐Ÿ‡ง Licensed under the MIT License.


๐Ÿค– Penghargaan & Pengakuan / Acknowledgements

Note

๐Ÿ‡ฎ๐Ÿ‡ฉ Ide, Konsep, & Visi Produk: Digagas oleh Ryansyah Putra.

๐Ÿ‡ฎ๐Ÿ‡ฉ Implementasi & Penulisan Kode: Dibangun dan dibantu sepenuhnya oleh AI Coding Assistant (Antigravity / Gemini).

Project ini dibuat berlandaskan ide untuk mempermudah ekosistem pengembang Flutter dalam mendukung perangkat foldable dan flip secara plug-and-play tanpa kerumitan kode boilerplate.


๐Ÿ‡ฌ๐Ÿ‡ง Product Idea, Concept & Vision: Conceived by Ryansyah Putra.

๐Ÿ‡ฌ๐Ÿ‡ง Implementation & Code Writing: Built and fully assisted by AI Coding Assistant (Antigravity / Gemini).

This project was created with the goal of simplifying the Flutter developer ecosystem to support foldable and flip devices in a plug-and-play fashion, without boilerplate code complexity.

Libraries

flutter_foldable_kit
A comprehensive, zero-boilerplate Flutter library for Foldable, Flip, and Dual-Screen devices.