Skip to content

Commit

Permalink
Merge pull request #7 from GoltVik/feature/extending_api
Browse files Browse the repository at this point in the history
extended API
  • Loading branch information
Pilaba authored Jan 31, 2024
2 parents c4a2e17 + 41642ef commit d69c03c
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 185 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2.1.0
- Added more configuration options

## 2.0.1
- Fix typos and code format

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[![pub package](https://img.shields.io/pub/v/flutter_lints.svg)](https://pub.dev/packages/top_modal_sheet)

# top_modal_sheet

Simple modal sheet that appears from the top of the screen

## Installations

Add `top_modal_sheet: ^2.0.0` in your `pubspec.yaml` dependencies. And import it:
Add `top_modal_sheet: ^2.1.0` in your `pubspec.yaml` dependencies. And import it:

```dart
import 'package:top_modal_sheet/top_modal_sheet.dart';
Expand All @@ -20,8 +22,7 @@ MaterialButton(
elevation: 5,
child: const Text("Show TopModal 1"),
onPressed: () async {
var value = await showTopModalSheet<String?>(context, DumyModal());
var value = await showTopModalSheet<String?>(context, DummyModal());
setState(() { _topModalData = value; });
},
)
Expand All @@ -31,8 +32,9 @@ For a more detail example please take a look at the `example` folder.

## Example

<img src="https://raw.githubusercontent.com/Pilaba/TopModalSheet/master/example/A.png" width="250" height="450">
<img src="https://raw.githubusercontent.com/Pilaba/TopModalSheet/master/example/B.png" width="250" height="450">
<img src="https://raw.githubusercontent.com/Pilaba/TopModalSheet/master/example/screenshots/main_screen.png" width="250" height="450">
<img src="https://raw.githubusercontent.com/Pilaba/TopModalSheet/master/example/screenshots/top_modal.png" width="250" height="450">
<img src="https://raw.githubusercontent.com/Pilaba/TopModalSheet/master/example/screenshots/top_modal_result.png" width="250" height="450">

## -

Expand Down
Binary file removed example/A.png
Binary file not shown.
Binary file removed example/B.png
Binary file not shown.
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
140 changes: 64 additions & 76 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:top_modal_sheet/top_modal_sheet.dart';

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

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
Expand All @@ -29,18 +30,20 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.teal,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
home: const MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
String? _topModalData;
String _topModalData = "";

@override
Widget build(BuildContext context) {
Expand All @@ -49,94 +52,79 @@ class _MyHomePageState extends State<MyHomePage> {
centerTitle: true,
title: const Text("TopModalSheet sample"),
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
child: Column(
children: <Widget>[
Expanded(
child: Center(
child: Text(
"$_topModalData",
style: TextStyle(fontSize: 30),
),
)),
MaterialButton(
color: Colors.white,
elevation: 5,
child: const Text("Show TopModal 1"),
onPressed: () async {
var value =
await showTopModalSheet<String?>(context, DumyModal());

setState(() {
_topModalData = value;
});
},
)
],
body: Center(
child: Text(
_topModalData,
style: Theme.of(context).textTheme.headlineLarge,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton.extended(
elevation: 5,
label: const Text("Show TopModal 1"),
onPressed: _showTopModal,
),
);
}

Future<void> _showTopModal() async {
final value = await showTopModalSheet<String?>(
context,
const DummyModal(),
backgroundColor: Colors.white,
borderRadius: const BorderRadius.vertical(
bottom: Radius.circular(20),
),
);

if (value != null) setState(() => _topModalData = value);
}
}

class DumyModal extends StatelessWidget {
class DummyModal extends StatelessWidget {
const DummyModal({Key? key}) : super(key: key);

static const _values = ["CF Cruz Azul", "Monarcas FC"];

@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 20),
return SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
const Text("Choose Wisely",
style: TextStyle(color: Colors.teal, fontSize: 20),
textAlign: TextAlign.center),
const Text(
"Choose Wisely",
style: TextStyle(color: Colors.teal, fontSize: 20),
textAlign: TextAlign.center,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 5),
child: OutlinedButton(
child: Column(
children: [
FlutterLogo(
size: MediaQuery.of(context).size.height * .15,
),
Padding(
padding: EdgeInsets.symmetric(vertical: 2),
child: Text("CF Cruz Azul"),
)
],
),
onPressed: () {
Navigator.of(context).pop("CF Cruz Azul");
},
),
)),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 5, right: 10),
child: OutlinedButton(
child: Column(
children: [
FlutterLogo(
size: MediaQuery.of(context).size.height * .15,
children: _values
.map(
(value) => Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 5),
child: OutlinedButton(
child: Column(
children: [
FlutterLogo(
size: MediaQuery.of(context).size.height * .15,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 2),
child: Text(value),
)
],
),
onPressed: () => Navigator.pop(context, value),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 2),
child: Text("Monarcas FC"),
)
],
),
),
onPressed: () {
Navigator.of(context).pop("Monarcas FC");
},
),
))
],
)
.toList(),
),
const SizedBox(height: 16),
],
),
);
Expand Down
Loading

0 comments on commit d69c03c

Please sign in to comment.