ios_willpop_transition_theme 0.0.1 ios_willpop_transition_theme: ^0.0.1 copied to clipboard
A Flutter package to solve the conflict between ios sliding back and Willpop.
import 'package:flutter/material.dart';
import 'package:ios_willpop_transition_theme/ios_willpop_transition_theme.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData(
pageTransitionsTheme: const PageTransitionsTheme(
builders: {
TargetPlatform.iOS: IosWillpopTransitionsBuilder(),
TargetPlatform.android: IosWillpopTransitionsBuilder(),
TargetPlatform.macOS: IosWillpopTransitionsBuilder(),
},
),
primarySwatch: Colors.blue,
),
home: const Home(),
);
}
}
class Home extends StatelessWidget {
const Home({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Example')),
body: Center(
// Consumer is a widget that allows you reading providers.
// You could also use the hook "ref.watch(" if you uses flutter_hooks
child: ElevatedButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => const TestPage(),
));
},
child: const Text('Push'),
),
),
);
}
}
class TestPage extends StatefulWidget {
const TestPage({Key? key}) : super(key: key);
@override
State<TestPage> createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
final bool? result = await showDialog(
context: context,
builder: (_) => Center(
widthFactor: 1,
child: Container(
color: Colors.white,
padding: const EdgeInsets.all(10),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <bool>[false, true]
.map((value) => TextButton(
onPressed: () => Navigator.pop(context, value),
child: Text(value.toString()),
))
.toList(),
),
),
),
);
return result == true;
},
child: Scaffold(
appBar: AppBar(title: const Text('TestPage')),
body: const Center(child: Text('TestPage')),
),
);
}
}