Skip to content

Commit

Permalink
Merge pull request #3 from Impaktfull/feat/improve-example
Browse files Browse the repository at this point in the history
feat: Improved the example project
  • Loading branch information
vanlooverenkoen authored Feb 10, 2024
2 parents 173aa56 + 6c79aa7 commit 2719659
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 97 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ and an easy to use API.

# Demo



https://github.com/Impaktfull/flutter_snacky/assets/21172855/3d41ff0b-11e5-402d-9b2d-a803200f65c1


https://raw.githubusercontent.com/impaktfull/flutter_snacky/master/assets/preview.dart

# Usage

Expand Down
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/preview.mp4
Binary file not shown.
152 changes: 126 additions & 26 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:snacky/snacky.dart';

const colorAccent = Color(0xFF7D64F2);
const colorPrimary = Color(0xFF1A1A1A);
void main() {
runApp(const MyApp());
}
Expand All @@ -11,10 +13,13 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SnackyConfiguratorWidget(
snackyBuilder: SimpleSnackyBuilder(
borderRadius: BorderRadius.circular(4),
),
app: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
colorScheme: ColorScheme.fromSeed(seedColor: colorAccent),
useMaterial3: true,
),
home: const HomeScreen(),
Expand All @@ -29,71 +34,166 @@ class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Snacky Example'),
),
body: ListView(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16).add(MediaQuery.of(context).padding),
children: [
FilledButton(
onPressed: () {
Image.asset(
'../assets/logo.png',
height: 50,
),
const SizedBox(height: 16),
ExampleButton(
title: 'show success at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
type: SnackyType.success,
);
SnackyController.instance.showMessage(snacky);
},
),
ExampleButton(
title: 'show error at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
type: SnackyType.error,
);
SnackyController.instance.showMessage(snacky);
},
),
ExampleButton(
title: 'show warning at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
type: SnackyType.warning,
);
SnackyController.instance.showMessage(snacky);
},
),
ExampleButton(
title: 'show info at the top of the screen',
onTap: () {
const snacky = Snacky(
title: 'Top',
type: SnackyType.info,
);
SnackyController.instance.showMessage(snacky);
},
child: const Text('show snacky at the top of the screen'),
),
FilledButton(
onPressed: () {
const SizedBox(height: 32),
ExampleButton(
title: 'show success at the bottom of the screen',
onTap: () {
const snacky = Snacky(
title: 'Bottom',
type: SnackyType.success,
location: SnackyLocation.bottom,
);
SnackyController.instance.showMessage(snacky);
},
child: const Text('show snacky at the bottom of the screen'),
),
FilledButton(
onPressed: () {
ExampleButton(
title: 'show success that can be canceled',
onTap: () {
const snacky = Snacky(
title: 'Top (cancelable)',
type: SnackyType.success,
canBeClosed: true,
);
SnackyController.instance.showMessage(snacky);
},
child: const Text('show snacky that can be canceled'),
),
FilledButton(
onPressed: () {
ExampleButton(
title: 'show success that can be canceled by tap',
onTap: () {
final snacky = Snacky(
title: 'Top (tap to cancel)',
type: SnackyType.success,
onTap: () => SnackyController.instance.cancelAll(),
);
SnackyController.instance.showMessage(snacky);
},
child: const Text('show snacky that can be canceled by tap'),
),
FilledButton(
onPressed: () {
ExampleButton(
title: 'show successs that will stay open untill closed',
onTap: () {
const snacky = Snacky.openUntillClosed(
title: 'Top (open untill closed/cancelled)',
canBeClosed: true,
type: SnackyType.success,
);
SnackyController.instance.showMessage(snacky);
},
child: const Text('show snacky that will stay open untill closed'),
),
FilledButton(
onPressed: () => SnackyController.instance.cancelAll(),
child: const Text('cancel all snackies'),
ExampleButton.primary(
title: 'cancel all snackies',
onTap: () => SnackyController.instance.cancelAll(),
),
FilledButton(
onPressed: () => SnackyController.instance.cancelActiveSnacky(),
child: const Text('cancel active snacky'),
ExampleButton.primary(
title: 'cancel active snacky',
onTap: () => SnackyController.instance.cancelActiveSnacky(),
),
],
),
);
}
}

class ExampleButton extends StatelessWidget {
final String title;
final VoidCallback onTap;
final Color color;

const ExampleButton({
required this.title,
required this.onTap,
super.key,
}) : color = colorAccent;

const ExampleButton.primary({
required this.title,
required this.onTap,
super.key,
}) : color = colorPrimary;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Stack(
children: [
Container(
width: double.infinity,
color: color,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
child: const ColoredBox(color: Colors.transparent),
),
),
),
],
),
),
);
}
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.1"
version: "0.0.8"
source_span:
dependency: transitive
description:
Expand Down
4 changes: 3 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ dev_dependencies:
flutter_lints: ^2.0.0

flutter:
uses-material-design: true
uses-material-design: true
assets:
- ../assets/logo.png
2 changes: 2 additions & 0 deletions lib/snacky.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export 'src/builder/simple_snacky_builder.dart';
export 'src/builder/snacky_builder.dart';
export 'src/controller/snacky_controller.dart';
export 'src/model/cancelable_snacky.dart';
export 'src/model/snacky.dart';
export 'src/model/snacky_location.dart';
export 'src/model/snacky_type.dart';
export 'src/navigator/snacky_navigator_observer.dart';
export 'src/transition/slide_transition.dart';
export 'src/widget/base_snacky_widget.dart';
export 'src/widget/snacky_configurator_widget.dart';
Loading

0 comments on commit 2719659

Please sign in to comment.