Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Mode support and Info dialog #7

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
Expand All @@ -35,7 +35,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.richalerts"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
# android.enableR8=true
20 changes: 12 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

Expand Down Expand Up @@ -51,15 +51,19 @@ class _MyHomePageState extends State<MyHomePage> {
return RichAlertDialog(
alertTitle: richTitle("Alert title"),
alertSubtitle: richSubtitle("Subtitle"),
alertType: RichAlertType.WARNING,
alertType: RichAlertType.INFO,
actions: <Widget>[
FlatButton(
child: Text("OK"),
onPressed: (){Navigator.pop(context);},
ElevatedButton(
child: Text("OK"),
onPressed: () {
Navigator.pop(context);
},
),
FlatButton(
child: Text("Cancel"),
onPressed: (){Navigator.pop(context);},
ElevatedButton(
child: Text("Cancel"),
onPressed: () {
Navigator.pop(context);
},
),
],
);
Expand Down
13 changes: 13 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/nexus/dev/sdks/flutter_rc/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/nexus/projects/side/rich_alert"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=0.1.32"
export "FLUTTER_BUILD_NUMBER=0.1.32"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"
Binary file added lib/assets/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 44 additions & 32 deletions lib/rich_alert.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:ui';

import 'package:flutter/material.dart';

class RichAlertDialog extends StatefulWidget {
Expand All @@ -22,24 +23,24 @@ class RichAlertDialog extends StatefulWidget {
/// [Button] widget is rendered.
///
/// Typically a [List<Widget>] widget.
final List<Widget> actions;
final List<Widget>? actions;

/// Specifies how blur the screen overlay effect should be.
/// Higher values mean more blurred overlays.
final double blurValue;
final double? blurValue;

// Specifies the opacity of the screen overlay
final double backgroundOpacity;
final double? backgroundOpacity;

/// (Optional) User defined icon for the dialog. Advisable to use the
/// default icon matching the dialog type.
final Icon dialogIcon;
final Icon? dialogIcon;

RichAlertDialog({
Key key,
@required this.alertTitle,
@required this.alertSubtitle,
@required this.alertType,
Key? key,
required this.alertTitle,
required this.alertSubtitle,
required this.alertType,
this.actions,
this.blurValue,
this.backgroundOpacity,
Expand All @@ -54,17 +55,19 @@ class _RichAlertDialogState extends State<RichAlertDialog> {
RichAlertType.ERROR: AssetImage("packages/rich_alert/assets/error.png"),
RichAlertType.SUCCESS: AssetImage("packages/rich_alert/assets/success.png"),
RichAlertType.WARNING: AssetImage("packages/rich_alert/assets/warning.png"),
RichAlertType.INFO: AssetImage("packages/rich_alert/assets/info.png"),
};

Map<int, Color> _typeColor = {
RichAlertType.ERROR: Colors.red,
RichAlertType.SUCCESS: Colors.green,
RichAlertType.WARNING: Colors.blue,
RichAlertType.WARNING: Colors.orange,
RichAlertType.INFO: Colors.blue,
};

double deviceWidth;
double deviceHeight;
double dialogHeight;
late double deviceWidth;
double? deviceHeight;
double? dialogHeight;

@override
Widget build(BuildContext context) {
Expand All @@ -77,20 +80,22 @@ class _RichAlertDialogState extends State<RichAlertDialog> {
deviceHeight = orientation == Orientation.portrait
? screenSize.height
: screenSize.width;
dialogHeight = deviceHeight * (2 / 5);
dialogHeight = deviceHeight! * (2 / 5);

return MediaQuery(
data: MediaQueryData(),
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: widget.blurValue != null ? widget.blurValue : 3.0,
sigmaY: widget.blurValue != null ? widget.blurValue : 3.0,
sigmaX: widget.blurValue != null ? widget.blurValue! : 3.0,
sigmaY: widget.blurValue != null ? widget.blurValue! : 3.0,
),
child: Container(
height: deviceHeight,
color: Colors.white.withOpacity(widget.backgroundOpacity != null
? widget.backgroundOpacity
: 0.2),
color: Theme.of(context).brightness == Brightness.light
? Colors.white.withOpacity(widget.backgroundOpacity != null
? widget.backgroundOpacity!
: 0.2)
: Colors.grey[900],
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
Expand All @@ -111,17 +116,20 @@ class _RichAlertDialogState extends State<RichAlertDialog> {
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0)),
),
color: Colors.white,
color:
Theme.of(context).brightness == Brightness.light
? Colors.white
: Colors.grey[800],
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: dialogHeight / 4),
SizedBox(height: dialogHeight! / 4),
widget.alertTitle,
SizedBox(height: dialogHeight / 10),
SizedBox(height: dialogHeight! / 10),
widget.alertSubtitle,
SizedBox(height: dialogHeight / 10),
SizedBox(height: dialogHeight! / 10),
widget.actions != null &&
widget.actions.isNotEmpty
widget.actions!.isNotEmpty
? _buildActions()
: _defaultAction(context),
],
Expand All @@ -130,9 +138,9 @@ class _RichAlertDialogState extends State<RichAlertDialog> {
),
),
Positioned(
bottom: dialogHeight - 50,
bottom: dialogHeight! - 50,
child: widget.dialogIcon != null
? widget.dialogIcon
? widget.dialogIcon!
: _defaultIcon(),
),
],
Expand All @@ -149,25 +157,27 @@ class _RichAlertDialogState extends State<RichAlertDialog> {
return Container(
child: Row(
mainAxisSize: MainAxisSize.min,
children: widget.actions,
children: widget.actions!,
),
);
}

Image _defaultIcon() {
return Image(
image: _typeAsset[widget.alertType],
width: deviceHeight / 7,
height: deviceHeight / 7,
image: _typeAsset[widget.alertType]!,
width: deviceHeight! / 7,
height: deviceHeight! / 7,
);
}

Container _defaultAction(BuildContext context) {
return Container(
alignment: Alignment.center,
child: RaisedButton(
elevation: 2.0,
color: _typeColor[widget.alertType],
child: ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 2.0,
backgroundColor: _typeColor[widget.alertType],
),
child: Text(
"GOT IT",
style: TextStyle(color: Colors.white),
Expand Down Expand Up @@ -205,4 +215,6 @@ class RichAlertType {

/// Indicates a warning dialog by providing a warning icon.
static const int WARNING = 2;

static const int INFO = 3;
}
37 changes: 37 additions & 0 deletions my_example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
10 changes: 10 additions & 0 deletions my_example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 27321ebbad34b0a3fafe99fac037102196d655ff
channel: stable

project_type: app
16 changes: 16 additions & 0 deletions my_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# my_example

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
7 changes: 7 additions & 0 deletions my_example/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
67 changes: 67 additions & 0 deletions my_example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.my_example"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
7 changes: 7 additions & 0 deletions my_example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.my_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Loading