flutter_split_layout 0.0.3 copy "flutter_split_layout: ^0.0.3" to clipboard
flutter_split_layout: ^0.0.3 copied to clipboard

This is Flutter Split Layout package.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_split_layout/flutter_split_layout.dart';

import 'src/my_primary_page.dart';
import 'src/my_secondary_page.dart';

enum DeviceType { phone, tablet }

DeviceType getDeviceType() {
  final data = MediaQueryData.fromView(
      WidgetsBinding.instance.platformDispatcher.views.single);
  return data.size.shortestSide < 550 ? DeviceType.phone : DeviceType.tablet;
}

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late FlutterSplitController splitController;

  @override
  void initState() {
    super.initState();

    splitController = FlutterSplitController();

    switch (getDeviceType()) {
      case DeviceType.phone:
        splitController.primaryNavigatorKey = null;
        splitController.secondaryNavigatorKey = null;
        break;
      case DeviceType.tablet:
        splitController.primaryNavigatorKey = GlobalKey<NavigatorState>();
        splitController.secondaryNavigatorKey = GlobalKey<NavigatorState>();
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    const title = 'Flutter Demo';
    final themeData = ThemeData(
      colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      useMaterial3: true,
    );

    switch (getDeviceType()) {
      case DeviceType.phone:
        return MaterialApp(
          title: title,
          theme: themeData,
          home: const MyPrimaryPage(),
        );
      case DeviceType.tablet:
        return FlutterSplitMaterialApp(
          controller: splitController,
          primaryApp: MaterialApp(
            title: title,
            theme: themeData,
            home: const MyPrimaryPage(),
          ),
          secondaryApp: MaterialApp(
            title: title,
            theme: themeData,
            home: const MySecondaryPage(),
          ),
        );
    }
  }
}
1
likes
140
points
36
downloads

Publisher

unverified uploader

Weekly Downloads

This is Flutter Split Layout package.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_split_layout