Skip to content

Commit

Permalink
Add flat property to popup.button
Browse files Browse the repository at this point in the history
  • Loading branch information
jaweii committed Dec 13, 2019
1 parent 129f7cb commit a59871e
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Add dependency to you `pubspec.yaml`:

```
dependencies:
flutter_beautiful_popup: ^1.4.1
flutter_beautiful_popup: ^1.5.0
```

Import the dependency:
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ beautiful_popup, 承包你的应用弹窗。[Live Demo](https://jaweii.github.io

```
dependencies:
flutter_beautiful_popup: ^1.4.1
flutter_beautiful_popup: ^1.5.0
```

引入依赖项:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.example

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.4.1"
version: "1.5.0"
flutter_colorpicker:
dependency: "direct main"
description:
Expand Down
30 changes: 30 additions & 0 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

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

import 'package:example/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
2 changes: 1 addition & 1 deletion lib/templates/BlueRocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TemplateBlueRocket extends BeautifulPopupTemplate {
);
}
return SizedBox(
width: percentW(100),
width: percentW(54),
child: Opacity(
opacity: 0.9,
child: AutoSizeText(
Expand Down
13 changes: 8 additions & 5 deletions lib/templates/Common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typedef Widget BeautifulPopupButton({
@required void Function() onPressed,
TextStyle labelStyle,
bool outline,
bool flat,
});

/// You can extend this class to custom your own template.
Expand Down Expand Up @@ -160,23 +161,25 @@ abstract class BeautifulPopupTemplate extends StatefulWidget {
@required String label,
@required void Function() onPressed,
bool outline = false,
bool flat = false,
TextStyle labelStyle = const TextStyle(),
}) {
final gradient = LinearGradient(colors: [
primaryColor.withOpacity(0.5),
primaryColor,
]);
final double elevation = outline ? 0 : 2;
final double elevation = (outline || flat) ? 0 : 2;
final labelColor =
outline ? primaryColor : Colors.white.withOpacity(0.95);
(outline || flat) ? primaryColor : Colors.white.withOpacity(0.95);
final decoration = BoxDecoration(
gradient: outline ? null : gradient,
gradient: (outline || flat) ? null : gradient,
borderRadius: BorderRadius.all(Radius.circular(80.0)),
border: Border.all(
color: outline ? primaryColor : Colors.transparent,
width: outline ? 1 : 0,
width: (outline && !flat) ? 1 : 0,
),
);
final minHeight = 40.0 - (outline ? 2 : 0);
return RaisedButton(
color: Colors.transparent,
elevation: elevation,
Expand All @@ -187,7 +190,7 @@ abstract class BeautifulPopupTemplate extends StatefulWidget {
child: Container(
constraints: BoxConstraints(
minWidth: 100,
minHeight: 40.0,
minHeight: minHeight,
),
alignment: Alignment.center,
child: Text(
Expand Down
18 changes: 11 additions & 7 deletions lib/templates/Gift.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ class TemplateGift extends BeautifulPopupTemplate {
@required String label,
@required void Function() onPressed,
bool outline = false,
bool flat = false,
TextStyle labelStyle = const TextStyle(),
}) {
final gradient = LinearGradient(colors: [
options.primaryColor.withOpacity(0.9),
options.primaryColor.withOpacity(0.7),
primaryColor.withOpacity(0.5),
primaryColor,
]);
final double elevation = outline ? 0 : 2;
final double elevation = (outline || flat) ? 0 : 2;
final labelColor =
(outline || flat) ? primaryColor : Colors.white.withOpacity(0.95);
final decoration = BoxDecoration(
gradient: outline ? null : gradient,
gradient: (outline || flat) ? null : gradient,
borderRadius: BorderRadius.all(Radius.circular(80.0)),
border: Border.all(
color: outline ? Colors.white.withOpacity(0.95) : Colors.transparent,
width: outline ? 2 : 0,
color: outline ? primaryColor : Colors.transparent,
width: (outline && !flat) ? 1 : 0,
),
);
final minHeight = 40.0 - (outline ? 4 : 0);
return RaisedButton(
color: Colors.transparent,
elevation: elevation,
Expand All @@ -49,7 +53,7 @@ class TemplateGift extends BeautifulPopupTemplate {
child: Container(
constraints: BoxConstraints(
minWidth: 100,
minHeight: 40.0 - (outline ? 4 : 0),
minHeight: minHeight,
),
alignment: Alignment.center,
child: Text(
Expand Down
1 change: 1 addition & 0 deletions lib/templates/OrangeRocket2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TemplateOrangeRocket2 extends BeautifulPopupTemplate {
),
Positioned(
top: percentH(42),
width: percentW(54),
child: title,
),
Positioned(
Expand Down
18 changes: 11 additions & 7 deletions lib/templates/RedPacket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,25 @@ class TemplateRedPacket extends BeautifulPopupTemplate {
@required String label,
@required void Function() onPressed,
bool outline = false,
bool flat = false,
TextStyle labelStyle = const TextStyle(),
}) {
final gradient = LinearGradient(colors: [
Colors.yellowAccent.withOpacity(0.75),
Colors.yellowAccent.withOpacity(0.5),
primaryColor.withOpacity(0.5),
primaryColor,
]);
final double elevation = outline ? 0 : 2;
final double elevation = (outline || flat) ? 0 : 2;
final labelColor =
(outline || flat) ? primaryColor : Colors.white.withOpacity(0.95);
final decoration = BoxDecoration(
gradient: outline ? null : gradient,
gradient: (outline || flat) ? null : gradient,
borderRadius: BorderRadius.all(Radius.circular(80.0)),
border: Border.all(
color: outline ? Colors.white.withOpacity(0.95) : Colors.transparent,
width: outline ? 2 : 0,
color: outline ? primaryColor : Colors.transparent,
width: (outline && !flat) ? 1 : 0,
),
);
final minHeight = 40.0 - (outline ? 2 : 0);
return RaisedButton(
color: Colors.transparent,
elevation: elevation,
Expand All @@ -92,7 +96,7 @@ class TemplateRedPacket extends BeautifulPopupTemplate {
child: Container(
constraints: BoxConstraints(
minWidth: 100,
minHeight: 40.0 - (outline ? 4 : 0),
minHeight: minHeight,
),
alignment: Alignment.center,
child: Text(
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/Success.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TemplateSuccess extends BeautifulPopupTemplate {
child: background,
),
Positioned(
top: percentH(48),
top: percentH(46),
child: title,
),
Positioned(
Expand Down
20 changes: 12 additions & 8 deletions lib/templates/Thumb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TemplateThumb extends BeautifulPopupTemplate {
);
}
return SizedBox(
width: percentW(100),
width: percentW(54),
child: Opacity(
opacity: 0.9,
child: AutoSizeText(
Expand All @@ -52,21 +52,25 @@ class TemplateThumb extends BeautifulPopupTemplate {
@required String label,
@required void Function() onPressed,
bool outline = false,
bool flat = false,
TextStyle labelStyle = const TextStyle(),
}) {
final gradient = LinearGradient(colors: [
Colors.white.withOpacity(0.25),
Colors.white.withOpacity(0.05),
primaryColor.withOpacity(0.5),
primaryColor,
]);
final double elevation = outline ? 0 : 2;
final double elevation = (outline || flat) ? 0 : 2;
final labelColor =
(outline || flat) ? primaryColor : Colors.white.withOpacity(0.95);
final decoration = BoxDecoration(
gradient: outline ? null : gradient,
gradient: (outline || flat) ? null : gradient,
borderRadius: BorderRadius.all(Radius.circular(80.0)),
border: Border.all(
color: outline ? Colors.white.withOpacity(0.95) : Colors.transparent,
width: outline ? 1 : 0,
color: outline ? primaryColor : Colors.transparent,
width: (outline && !flat) ? 1 : 0,
),
);
final minHeight = 40.0 - (outline ? 2 : 0);
return RaisedButton(
color: Colors.transparent,
elevation: elevation,
Expand All @@ -77,7 +81,7 @@ class TemplateThumb extends BeautifulPopupTemplate {
child: Container(
constraints: BoxConstraints(
minWidth: 100,
minHeight: 40.0 - (outline ? 4 : 0),
minHeight: minHeight,
),
alignment: Alignment.center,
child: Text(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_beautiful_popup
description: A flutter package to help you beautify your app popups.
version: 1.4.1
version: 1.5.0
homepage: https://jaweii.github.io/Flutter_beautiful_popup/example/build/web

environment:
Expand Down

0 comments on commit a59871e

Please sign in to comment.