Skip to content

Commit

Permalink
Merge pull request #8 from chenenyu/dev
Browse files Browse the repository at this point in the history
0.3.2
  • Loading branch information
chenenyu authored Sep 23, 2021
2 parents 57a1756 + 50c3b5f commit f3d859f
Show file tree
Hide file tree
Showing 29 changed files with 139 additions and 122 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.3.2] - 2021/09/23.

* NEW API: `findRoute(String routeName)`.
* Add `flutter_lints`.

## [0.3.1] - 2021/09/01.

* Bug fixes.
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,13 @@ class _NestedPageViewState extends State<NestedPageView> with SingleTickerProvid
```

### Other API
### Other APIs

* Find a route according to a specific name.

```
defaultLifecycleObserver.findRoute('route_name');
```
* Remove a route according to a specific name.
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
1 change: 1 addition & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
26 changes: 13 additions & 13 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:lifecycle/lifecycle.dart';
import 'overlay_log.dart';

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

@override
_HomePageState createState() {
Expand Down Expand Up @@ -33,49 +33,49 @@ class _HomePageState extends State<HomePage>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
title: const Text(
'Home Page',
),
),
body: Center(
child: Column(
children: <Widget>[
ElevatedButton(
child: Text('Open Sub1Page'),
child: const Text('Open Sub1Page'),
onPressed: () {
Navigator.of(context).pushNamed('sub1');
},
),
ElevatedButton(
child: Text('Open Sub2Page'),
child: const Text('Open Sub2Page'),
onPressed: () {
Navigator.of(context).pushNamed('sub2');
},
),
ElevatedButton(
child: Text('Open Dialog'),
child: const Text('Open Dialog'),
onPressed: () {
showDialog(
context: context,
routeSettings: RouteSettings(name: 'dialog'),
routeSettings: const RouteSettings(name: 'dialog'),
builder: (context) {
return LifecycleWrapper(
onLifecycleEvent: (event) {
log.add('Dialog#${event.toString()}');
},
child: AlertDialog(
content: Text(
content: const Text(
'This is a dialog.',
),
actions: <Widget>[
TextButton(
child: Text('Dismiss'),
child: const Text('Dismiss'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text('Open Sub1Page'),
child: const Text('Open Sub1Page'),
onPressed: () {
Navigator.of(context).pushNamed('sub1');
},
Expand All @@ -88,25 +88,25 @@ class _HomePageState extends State<HomePage>
},
),
ElevatedButton(
child: Text('Open MyPageView'),
child: const Text('Open MyPageView'),
onPressed: () {
Navigator.of(context).pushNamed('pageview');
},
),
ElevatedButton(
child: Text('Open MyTabView'),
child: const Text('Open MyTabView'),
onPressed: () {
Navigator.of(context).pushNamed('tabview');
},
),
ElevatedButton(
child: Text('Open NestedPageView'),
child: const Text('Open NestedPageView'),
onPressed: () {
Navigator.of(context).pushNamed('nested');
},
),
ElevatedButton(
child: Text('Open Nav2.0'),
child: const Text('Open Nav2.0'),
onPressed: () {
Navigator.of(context).pushNamed('nav2');
},
Expand Down
18 changes: 10 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import 'sub2_page.dart';
import 'tabview.dart';

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

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

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -25,17 +27,17 @@ class MyApp extends StatelessWidget {
),
navigatorObservers: [defaultLifecycleObserver],
routes: {
'sub1': (_) => Sub1Page(),
'sub2': (_) => Sub2Page(),
'pageview': (_) => MyPageView(),
'tabview': (_) => MyTabView(),
'nested': (_) => NestedPageView(),
'nav2': (_) => Nav2Home(),
'sub1': (_) => const Sub1Page(),
'sub2': (_) => const Sub2Page(),
'pageview': (_) => const MyPageView(),
'tabview': (_) => const MyTabView(),
'nested': (_) => const NestedPageView(),
'nav2': (_) => const Nav2Home(),
},
home: Builder(
builder: (context) {
LogEntry.init(context);
return HomePage();
return const HomePage();
},
),
);
Expand Down
2 changes: 1 addition & 1 deletion example/lib/nav2_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'nav2_page2.dart';
import 'overlay_log.dart';

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

@override
_Nav2HomeState createState() {
Expand Down
6 changes: 3 additions & 3 deletions example/lib/nav2_page1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'overlay_log.dart';
class Nav2Page1 extends StatefulWidget {
final VoidCallback onShowPage2;

Nav2Page1({Key? key, required this.onShowPage2}) : super(key: key);
const Nav2Page1({Key? key, required this.onShowPage2}) : super(key: key);

@override
_Nav2Page1State createState() {
Expand Down Expand Up @@ -38,7 +38,7 @@ class _Nav2Page1State extends State<Nav2Page1>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page1'),
title: const Text('Page1'),
leading: BackButton(
onPressed: () {
Navigator.of(context, rootNavigator: true).maybePop();
Expand All @@ -48,7 +48,7 @@ class _Nav2Page1State extends State<Nav2Page1>
body: Center(
child: TextButton(
onPressed: widget.onShowPage2,
child: Text('Open Page2'),
child: const Text('Open Page2'),
),
),
);
Expand Down
6 changes: 3 additions & 3 deletions example/lib/nav2_page2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'overlay_log.dart';
class Nav2Page2 extends StatefulWidget {
final VoidCallback onHidePage1;

Nav2Page2({Key? key, required this.onHidePage1}) : super(key: key);
const Nav2Page2({Key? key, required this.onHidePage1}) : super(key: key);

@override
_Nav2Page2State createState() {
Expand Down Expand Up @@ -38,7 +38,7 @@ class _Nav2Page2State extends State<Nav2Page2>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Page2'),
title: const Text('Page2'),
// leading: BackButton(
// onPressed: () {
// Navigator.of(context, rootNavigator: true).maybePop();
Expand All @@ -48,7 +48,7 @@ class _Nav2Page2State extends State<Nav2Page2>
body: Center(
child: TextButton(
onPressed: widget.onHidePage1,
child: Text('Hide Page1'),
child: const Text('Hide Page1'),
),
),
);
Expand Down
17 changes: 9 additions & 8 deletions example/lib/nested_pageview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import 'package:lifecycle/lifecycle.dart';
import 'overlay_log.dart';

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

@override
_NestedPageViewState createState() => _NestedPageViewState();
}

Expand All @@ -15,8 +16,8 @@ class _NestedPageViewState extends State<NestedPageView>
late TabController _tabController;

final List<Tab> myTabs = <Tab>[
Tab(text: 'left'),
Tab(text: 'right'),
const Tab(text: 'left'),
const Tab(text: 'right'),
];

@override
Expand All @@ -37,7 +38,7 @@ class _NestedPageViewState extends State<NestedPageView>
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('NestedPageView'),
title: const Text('NestedPageView'),
bottom: TabBar(
controller: _tabController,
tabs: myTabs,
Expand All @@ -57,10 +58,10 @@ class _NestedPageViewState extends State<NestedPageView>
log.add('OuterPage@0#${event.toString()}');
},
wantKeepAlive: true,
child: Center(
child: const Center(
child: Text(
'This is the first tab',
style: const TextStyle(fontSize: 20),
style: TextStyle(fontSize: 20),
),
),
),
Expand Down Expand Up @@ -97,7 +98,7 @@ class _NestedPageViewState extends State<NestedPageView>
);
}
},
child: Text('Next'),
child: const Text('Next'),
),
),
),
Expand All @@ -121,7 +122,7 @@ class _NestedPageViewState extends State<NestedPageView>
);
}
},
child: Text('Previous'),
child: const Text('Previous'),
),
),
),
Expand Down
8 changes: 4 additions & 4 deletions example/lib/overlay_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LogEntry extends StatefulWidget {
}

class LogEntryState extends State<LogEntry> {
ScrollController _controller = ScrollController();
final ScrollController _controller = ScrollController();

@override
void initState() {
Expand Down Expand Up @@ -63,13 +63,13 @@ class LogEntryState extends State<LogEntry> {
ListView.builder(
controller: _controller,
shrinkWrap: true,
padding: EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
itemCount: _logs.length,
itemBuilder: (context, index) {
final String log = _logs[index];
return Text(
log,
style: TextStyle(
style: const TextStyle(
color: Colors.white70,
fontSize: 14,
),
Expand All @@ -82,7 +82,7 @@ class LogEntryState extends State<LogEntry> {
child: IconButton(
iconSize: 16,
padding: EdgeInsets.zero,
icon: Icon(
icon: const Icon(
Icons.clear,
color: Colors.white,
),
Expand Down
19 changes: 10 additions & 9 deletions example/lib/pageview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import 'package:lifecycle/lifecycle.dart';
import 'overlay_log.dart';

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

@override
_MyPageViewState createState() => _MyPageViewState();
}

Expand All @@ -28,7 +29,7 @@ class _MyPageViewState extends State<MyPageView> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('MyPageView'),
title: const Text('MyPageView'),
),
body: ParentPageLifecycleWrapper(
controller: _pageController,
Expand Down Expand Up @@ -59,31 +60,31 @@ class _MyPageViewState extends State<MyPageView> {
);
}
},
child: Text('Next'),
child: const Text('Next'),
),
ElevatedButton(
onPressed: () {
showDialog(
context: context,
routeSettings: RouteSettings(name: 'dialog'),
routeSettings: const RouteSettings(name: 'dialog'),
builder: (context) {
return LifecycleWrapper(
onLifecycleEvent: (event) {
log.add('Dialog#${event.toString()}');
},
child: AlertDialog(
content: Text(
content: const Text(
'This is a dialog.',
),
actions: <Widget>[
TextButton(
child: Text('Dismiss'),
child: const Text('Dismiss'),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text('Open Sub1Page'),
child: const Text('Open Sub1Page'),
onPressed: () {
Navigator.of(context).pushNamed('sub1');
},
Expand All @@ -94,7 +95,7 @@ class _MyPageViewState extends State<MyPageView> {
},
);
},
child: Text('Open dialog'),
child: const Text('Open dialog'),
),
],
),
Expand Down Expand Up @@ -122,7 +123,7 @@ class _MyPageViewState extends State<MyPageView> {
);
}
},
child: Text('Previous'),
child: const Text('Previous'),
),
],
),
Expand Down
Loading

0 comments on commit f3d859f

Please sign in to comment.