n_slide_popup 0.0.1
n_slide_popup: ^0.0.1 copied to clipboard
A flutter pop-up view with its direction from aligment type.
import 'package:flutter/material.dart';
import 'package:n_slide_popup/n_slide_popup.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const MyHomePage(title: 'Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<Alignment> alignments = [
Alignment.topLeft,
Alignment.topCenter,
Alignment.topRight,
Alignment.centerLeft,
Alignment.center,
Alignment.centerRight,
Alignment.bottomLeft,
Alignment.bottomCenter,
Alignment.bottomRight,
];
var alignment = Alignment.center;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text("direction from Alignment."),
Wrap(
spacing: 8,
runSpacing: 8,
children: [
...alignments.map((e) {
var name = e.toString().split('.')[1];
return ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
elevation: 0,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
minimumSize: const Size(64, 36),
),
onPressed: () {
alignment = e;
debugPrint("$alignment ${alignment.x} ${alignment.y}");
onPopupRoute();
},
child: Text(
name,
style: TextStyle(color: Colors.white),
),
);
}),
],
)
],
),
);
}
Future<void> onPopupRoute() async {
final route = NSlidePopupRoute(
from: alignment,
builder: (_) {
return buildPopupView(alignment: alignment, argsDismiss: {"b": "88"});
},
);
final result = await Navigator.of(context).push(route);
print(["result", result.runtimeType, result]);
}
Widget buildPopupView({required Alignment alignment, Map<String, dynamic>? argsDismiss}) {
return Align(
alignment: alignment,
child: Container(
width: 300,
height: 400,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.green,
border: Border.all(color: Colors.blue),
borderRadius: BorderRadius.all(Radius.circular(0)),
),
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pop(argsDismiss);
},
child: Text("dismiss"),
),
),
);
}
}