Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fluttercommunity/breakpoint
Breakpoint - A Flutter plugin to calculate the material design breakpoints. Maintainer: @rodydavis
https://github.com/fluttercommunity/breakpoint
breakpoint flutter layout-builder material material-design
Last synced: 3 months ago
JSON representation
Breakpoint - A Flutter plugin to calculate the material design breakpoints. Maintainer: @rodydavis
- Host: GitHub
- URL: https://github.com/fluttercommunity/breakpoint
- Owner: fluttercommunity
- License: mit
- Created: 2019-05-24T18:16:28.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-16T01:30:26.000Z (over 2 years ago)
- Last Synced: 2024-06-20T08:06:34.441Z (5 months ago)
- Topics: breakpoint, flutter, layout-builder, material, material-design
- Language: Dart
- Homepage: https://fluttercommunity.github.io/breakpoint/
- Size: 12.9 MB
- Stars: 109
- Watchers: 6
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Flutter Community: breakpoint](https://fluttercommunity.dev/_github/header/breakpoint)](https://github.com/fluttercommunity/community)
[![Buy Me A Coffee](https://img.shields.io/badge/Donate-Buy%20Me%20A%20Coffee-yellow.svg)](https://www.buymeacoffee.com/rodydavis)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WSH3GVC49GNNJ)
![github pages](https://github.com/fluttercommunity/breakpoint/workflows/github%20pages/badge.svg)
[![GitHub stars](https://img.shields.io/github/stars/fluttercommunity/breakpoint?color=blue)](https://github.com/fluttercommunity/breakpoint)
[![breakpoint](https://img.shields.io/pub/v/breakpoint.svg)](https://pub.dev/packages/breakpoint)# breakpoint
View the online demo [here](https://fluttercommunity.github.io/breakpoint/#/)!
## Overview
Follows Material Design [Docs](https://material.io/design/layout/responsive-layout-grid.html#breakpoints).
![breakpoint](https://github.com/fluttercommunity/breakpoint/blob/master/screenshots/breakpoint.png)
## Usage
When you are wanting to calculate the breakpoint of a widget that may not take up the full screen. This needs `BoxConstraints` but can be provided by the layout builder.
``` dart
final _breakpoint = Breakpoint.fromConstraints(constraints);
```When a widget always takes up thye full screen.
``` dart
final _breakpoint = Breakpoint.fromMediaQuery(context);
```Use `BreakpointBuilder` if you want the layout builder wrapped for you.
``` dart
return BreakpointBuilder(
builder: (context, breakpoint) {
print('Breakpoint: $breakpoint');
return Container();
},
);
```## Example
``` dart
import 'dart:io';import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:breakpoint/breakpoint.dart';/// main is entry point of Flutter application
void main() {
// Desktop platforms aren't a valid platform.
_setTargetPlatformForDesktop();return runApp(MyApp());
}/// If the current platform is desktop, override the default platform to
/// a supported platform (iOS for macOS, Android for Linux and Windows).
/// Otherwise, do nothing.
void _setTargetPlatformForDesktop() {
TargetPlatform targetPlatform;
if (Platform.isMacOS) {
targetPlatform = TargetPlatform.iOS;
} else if (Platform.isLinux || Platform.isWindows) {
targetPlatform = TargetPlatform.android;
}
if (targetPlatform != null) {
debugDefaultTargetPlatformOverride = targetPlatform;
}
}class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (_, constraints) {
final _breakpoint = Breakpoint.fromConstraints(constraints);
return Scaffold(
appBar: AppBar(
title: Text('Breakpoint Example: ${_breakpoint.toString()}'),
),
body: Container(
padding: EdgeInsets.all(_breakpoint.gutters),
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: _breakpoint.columns,
crossAxisSpacing: _breakpoint.gutters,
mainAxisSpacing: _breakpoint.gutters,
),
itemCount: 200,
itemBuilder: (_, index) {
return Container(
child: Card(
child: Text(
index.toString(),
),
),
);
},
),
),
);
});
}
}```