Skip to content
This repository was archived by the owner on May 14, 2023. It is now read-only.

Commit 2b7a028

Browse files
committed
Breakpoint system
1 parent 3d652bf commit 2b7a028

40 files changed

+445
-1438
lines changed

adaptive_breakpoints/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## [0.0.1] - TODO: Add release date.
1+
# [0.0.1] - August 12, 2020
22

3-
* TODO: Describe initial release.
3+
The initial release adds the [breakpoint system](https://material.io/design/layout/responsive-layout-grid.html#breakpoints)

adaptive_breakpoints/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ repo.
2525

2626
1. Make sure all the existing tests are passing by using the following command (from the root of the project): `$ flutter test test/`.
2727
1. Create a PR to merge the branch on your fork into `dart-code-viewer/master`.
28-
1. Add `JoseAlba` as reviewers on the PR. We will take a look and add any comments. When the PR is ready to be merged, we will merge it and update the package.
28+
1. Add `JoseAlba` as reviewer on the PR. I will take a look and add any comments. When the PR is ready to be merged, we will merge it and update the package.

adaptive_breakpoints/README.md

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,79 @@
11
# adaptive_breakpoints
22

3-
A new Flutter project.
3+
The `adaptive_breakpoints` package for Flutter allows you to use the adaptive [breakpoints entries](https://material.io/design/layout/responsive-layout-grid.html#breakpoints) from the [Material Design System](https://material.io/).
44

55
## Getting Started
66

7-
This project is a starting point for a Flutter application.
7+
This package provides the material breakpoint entries for adaptive/responsive development in Flutter.
88

9-
A few resources to get you started if this is your first Flutter project:
9+
Firs, add the `adaptive_breakpoints` package to your pubspec dependencies.
1010

11-
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12-
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
11+
To import `adaptive_breakpoints`:
1312

14-
For help getting started with Flutter, view our
15-
[online documentation](https://flutter.dev/docs), which offers tutorials,
16-
samples, guidance on mobile development, and a full API reference.
13+
```dart
14+
import 'package:adaptive_breakpoints/adaptive_breakpoints.dart
15+
```
16+
17+
Here is an example of how to implement the Adaptive Breakpoint entries in Flutter Development.
18+
19+
```dart
20+
import 'package:flutter/material.dart';
21+
import 'package:adaptive_breakpoints/adaptive_breakpoints.dart';
22+
23+
void main() {
24+
runApp(MyApp());
25+
}
26+
27+
class MyApp extends StatelessWidget {
28+
@override
29+
Widget build(BuildContext context) {
30+
return MaterialApp(
31+
home: Scaffold(
32+
body: AdaptiveContainer(
33+
windowLimit: AdaptiveWindow.m,
34+
child: SizedBox(
35+
height: 300,
36+
child: Text('Adaptive Container'),
37+
),
38+
),
39+
),
40+
);
41+
}
42+
}
43+
44+
class AdaptiveContainer extends StatelessWidget {
45+
final AdaptiveWindow windowLimit;
46+
final Widget child;
47+
48+
const AdaptiveContainer({
49+
@required this.windowLimit,
50+
@required this.child,
51+
}) : assert(windowLimit != null),
52+
assert(child != null);
53+
54+
@override
55+
Widget build(BuildContext context) {
56+
return LayoutBuilder(
57+
builder: (BuildContext context, BoxConstraints constraints) {
58+
BreakpointSystemEntry entry =
59+
getBreakpointEntry(MediaQuery.of(context).size);
60+
if (entry.window == windowLimit) {
61+
return Container(
62+
constraints: BoxConstraints(
63+
maxWidth: entry.window.longestWidth,
64+
minWidth: entry.window.shortestWidth,
65+
),
66+
width: MediaQuery.of(context).size.width - (entry.margins * 2),
67+
margin: EdgeInsets.symmetric(horizontal: entry.margins),
68+
color: Colors.pink,
69+
child: child,
70+
);
71+
} else {
72+
return SizedBox();
73+
}
74+
},
75+
);
76+
}
77+
}
78+
79+
```
Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
# example
1+
# Adaptive breakpoint sample app
22

3-
A new Flutter project.
4-
5-
## Getting Started
6-
7-
This project is a starting point for a Flutter application.
8-
9-
A few resources to get you started if this is your first Flutter project:
10-
11-
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12-
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13-
14-
For help getting started with Flutter, view our
15-
[online documentation](https://flutter.dev/docs), which offers tutorials,
16-
samples, guidance on mobile development, and a full API reference.
3+
This example application demonstrates how to use [`adaptive_breakpoints`](https://pub.dev/packages/adaptive_breakpoints) within a simple Flutter app.

adaptive_breakpoints/example/lib/main.dart

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,53 @@ void main() {
66
}
77

88
class MyApp extends StatelessWidget {
9-
// This widget is the root of your application.
109
@override
1110
Widget build(BuildContext context) {
1211
return MaterialApp(
13-
title: 'Flutter Demo',
14-
theme: ThemeData(
15-
primarySwatch: Colors.blue,
12+
home: Scaffold(
13+
body: AdaptiveContainer(
14+
windowLimit: AdaptiveWindow.m,
15+
child: SizedBox(
16+
height: 300,
17+
child: Text('Adaptive Container'),
18+
),
19+
),
1620
),
17-
home: MyHomePage(title: 'Flutter Demo Home Page'),
1821
);
1922
}
2023
}
2124

22-
class MyHomePage extends StatefulWidget {
23-
MyHomePage({Key key, this.title}) : super(key: key);
24-
final String title;
25+
class AdaptiveContainer extends StatelessWidget {
26+
final AdaptiveWindow windowLimit;
27+
final Widget child;
2528

26-
@override
27-
_MyHomePageState createState() => _MyHomePageState();
28-
}
29-
30-
class _MyHomePageState extends State<MyHomePage> {
31-
int _counter = 0;
32-
33-
void _incrementCounter() {
34-
setState(() {
35-
_counter++;
36-
});
37-
}
29+
const AdaptiveContainer({
30+
@required this.windowLimit,
31+
@required this.child,
32+
}) : assert(windowLimit != null),
33+
assert(child != null);
3834

3935
@override
4036
Widget build(BuildContext context) {
41-
return Scaffold(
42-
appBar: AppBar(
43-
title: Text(widget.title),
44-
),
45-
body: Center(
46-
child: Column(
47-
mainAxisAlignment: MainAxisAlignment.center,
48-
children: <Widget>[
49-
Row(),
50-
Wrap(),
51-
],
52-
),
53-
),
54-
floatingActionButton: FloatingActionButton(
55-
onPressed: _incrementCounter,
56-
tooltip: 'Increment',
57-
child: Icon(Icons.add),
58-
), // This trailing comma makes auto-formatting nicer for build methods.
37+
return LayoutBuilder(
38+
builder: (BuildContext context, BoxConstraints constraints) {
39+
BreakpointSystemEntry entry =
40+
getBreakpointEntry(MediaQuery.of(context).size);
41+
if (entry.window == windowLimit) {
42+
return Container(
43+
constraints: BoxConstraints(
44+
maxWidth: entry.window.longestWidth,
45+
minWidth: entry.window.shortestWidth,
46+
),
47+
width: MediaQuery.of(context).size.width - (entry.margins * 2),
48+
margin: EdgeInsets.symmetric(horizontal: entry.margins),
49+
color: Colors.pink,
50+
child: child,
51+
);
52+
} else {
53+
return SizedBox();
54+
}
55+
},
5956
);
6057
}
6158
}

adaptive_breakpoints/example/macos/.gitignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

adaptive_breakpoints/example/macos/Flutter/Flutter-Debug.xcconfig

Lines changed: 0 additions & 1 deletion
This file was deleted.

adaptive_breakpoints/example/macos/Flutter/Flutter-Release.xcconfig

Lines changed: 0 additions & 1 deletion
This file was deleted.

adaptive_breakpoints/example/macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)