Skip to content

Commit

Permalink
fix: example warning
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoAiolia committed Jan 26, 2024
1 parent d68c5cc commit e1c233c
Show file tree
Hide file tree
Showing 19 changed files with 234 additions and 163 deletions.
5 changes: 3 additions & 2 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include: package:effective_dart/analysis_options.yaml
include: package:flutter_lints/flutter.yaml

linter:
rules:
public_member_api_docs: false
public_member_api_docs: false
library_private_types_in_public_api: false
23 changes: 13 additions & 10 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import 'src/utils/observer.dart';
import 'src/utils/simple_localizations.dart';

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

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

@override
// ignore: library_private_types_in_public_api
_MyAppState createState() => _MyAppState();
}

Expand All @@ -29,17 +32,17 @@ class _MyAppState extends State<MyApp> {
'flutter2flutter': (settings) => CupertinoPageRoute(
builder: (context) => Flutter2Flutter(index: settings.toJson.index),
settings: settings),
'tab1': (settings) =>
CupertinoPageRoute(builder: (context) => TabPage(), settings: settings),
'tab1': (settings) => CupertinoPageRoute(
builder: (context) => const TabPage(), settings: settings),
'transparent_flutter': (settings) => CupertinoPageRoute(
builder: (context) => TransparentPage(),
builder: (context) => const TransparentPage(),
settings: settings,
)
};

@override
Widget build(BuildContext context) {
final color = Color.fromARGB(255, 6, 210, 116);
const color = Color.fromARGB(255, 6, 210, 116);

final route = faraday.wrapper(
(settings) => routes[settings.name]?.call(settings),
Expand Down Expand Up @@ -69,11 +72,11 @@ class _MyAppState extends State<MyApp> {
DefaultCupertinoLocalizations.delegate,
GlobalCupertinoLocalizations.delegate
],
supportedLocales: [
supportedLocales: const [
Locale('en', ''),
Locale.fromSubtags(languageCode: 'zh')
],
theme: CupertinoThemeData(primaryColor: color),
theme: const CupertinoThemeData(primaryColor: color),
debugShowCheckedModeBanner: false,
onGenerateRoute: (_) => route,
);
Expand All @@ -84,7 +87,7 @@ class _MyAppState extends State<MyApp> {
location: BannerLocation.topEnd,
message: 'faraday',
color: color,
textStyle: TextStyle(
textStyle: const TextStyle(
color: CupertinoColors.white,
fontSize: 12 * 0.85,
fontWeight: FontWeight.w900,
Expand All @@ -104,9 +107,9 @@ class _MyAppState extends State<MyApp> {
behavior: HitTestBehavior.opaque,
child: Container(
color: CupertinoColors.lightBackgroundGray,
padding: EdgeInsets.only(left: 15.0, right: 15.0),
padding: const EdgeInsets.only(left: 15.0, right: 15.0),
alignment: Alignment.center,
child: Text.rich(
child: const Text.rich(
TextSpan(children: [
TextSpan(
text: '404',
Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/pages/example_page_scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _ExamplePageScaffoldState extends State<ExamplePageScaffold> {
middle: Text(widget.title ?? 'NoTitle'),
),
child: SafeArea(
minimum: EdgeInsets.all(16),
minimum: const EdgeInsets.all(16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down
38 changes: 21 additions & 17 deletions example/lib/src/pages/features/basic/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'pages/flutter_to_flutter.dart';
import 'pages/flutter_to_native.dart';

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

@override
_BasicState createState() => _BasicState();
}
Expand All @@ -32,20 +34,22 @@ class _BasicState extends State<Basic> {
}

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

@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
backgroundColor: CupertinoColors.secondarySystemBackground,
navigationBar: CupertinoNavigationBar(
navigationBar: const CupertinoNavigationBar(
middle: Text('All Basics'),
),
child: SafeArea(
child: Center(
child: ListView(
physics: AlwaysScrollableScrollPhysics(),
physics: const AlwaysScrollableScrollPhysics(),
children: [
Container(
margin: EdgeInsets.all(16.0),
margin: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: CupertinoColors.white,
borderRadius: BorderRadius.circular(8),
Expand All @@ -70,37 +74,37 @@ List<Widget> _buildActions(BuildContext context, {bool onlyBase = true}) {
begin: _Action.flutter,
end: _Action.native,
onTap: () => Navigator.of(context).push(
CupertinoPageRoute(builder: (_) => Flutter2NativePage()),
CupertinoPageRoute(builder: (_) => const Flutter2NativePage()),
),
),
Divider(height: 1),
const Divider(height: 1),
_Action(
title: S.of(context).basicNative2Flutter,
subTitle: 'viewController activity fragment',
begin: _Action.native,
end: _Action.flutter,
onTap: () => Navigator.of(context).nativePushNamed('native2flutter'),
),
Divider(height: 1),
const Divider(height: 1),
_Action(
title: S.of(context).basicFlutter2Flutter,
subTitle: S.of(context).basicFlutter2FlutterDescription,
begin: _Action.flutter,
end: _Action.flutter,
onTap: () => Navigator.of(context).push(
CupertinoPageRoute(builder: (_) => Flutter2Flutter()),
CupertinoPageRoute(builder: (_) => const Flutter2Flutter()),
),
),
];
if (onlyBase) return base;
return [
...base,
Divider(height: 1),
const Divider(height: 1),
_Action(
title: S.of(context).basicChild,
subTitle: S.of(context).basicChildDescription,
begin: _Action.flutter,
end: Icon(Icons.widgets),
end: const Icon(Icons.widgets),
onTap: () => Navigator.of(context).nativePushNamed('tabContainer'),
),
];
Expand All @@ -122,9 +126,9 @@ class _Action extends StatelessWidget {
required this.onTap,
}) : super(key: key);

static Widget get flutter => FlutterLogo();
static Widget get flutter => const FlutterLogo();
static Widget get native =>
Icon(Icons.mobile_screen_share, color: CupertinoColors.activeBlue);
const Icon(Icons.mobile_screen_share, color: CupertinoColors.activeBlue);

@override
Widget build(BuildContext context) {
Expand All @@ -142,31 +146,31 @@ class _Action extends StatelessWidget {
Row(
children: [
begin,
Icon(
const Icon(
Icons.arrow_right_alt,
color: CupertinoColors.tertiaryLabel,
),
end
],
),
SizedBox(height: 10),
const SizedBox(height: 10),
Text(
title,
style: TextStyle(
style: const TextStyle(
fontWeight: FontWeight.w500,
color: CupertinoColors.black),
),
Text(
subTitle,
maxLines: 2,
style: TextStyle(
style: const TextStyle(
fontSize: 12, color: CupertinoColors.secondaryLabel),
)
],
),
),
Spacer(),
Icon(
const Spacer(),
const Icon(
CupertinoIcons.right_chevron,
color: CupertinoColors.tertiaryLabel,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class _Flutter2FlutterState extends State<Flutter2Flutter> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
'Flutter 页面之间的跳转和纯flutter项目没有任何区别, navigator的所有api均可使用'),
),
TextButton(
child: Text('Open New Flutter Page'),
child: const Text('Open New Flutter Page'),
onPressed: () {
Navigator.of(context).push(
CupertinoPageRoute(
Expand All @@ -46,7 +46,7 @@ class _Flutter2FlutterState extends State<Flutter2Flutter> {
},
),
TextButton(
child: Text('Open New Flutter By New Container'),
child: const Text('Open New Flutter By New Container'),
onPressed: () => Navigator.of(context).nativePushNamed(
'flutter2flutter',
arguments: {'index': (widget.index ?? 1) * -1},
Expand Down
19 changes: 11 additions & 8 deletions example/lib/src/pages/features/basic/pages/flutter_to_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'package:g_faraday/g_faraday.dart';

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

@override
_Flutter2NativePageState createState() => _Flutter2NativePageState();
}
Expand All @@ -13,28 +15,29 @@ class _Flutter2NativePageState extends State<Flutter2NativePage> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
navigationBar: const CupertinoNavigationBar(
middle: Text('Flutter to Native'),
),
child: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('支持🍎和🍐两种方式打开'),
),
TextButton(
child: Text('🍎: Navigator.of(context)?.nativePushNamed'),
child:
const Text('🍎: Navigator.of(context)?.nativePushNamed'),
onPressed: () async {
_showResult(
context,
await Navigator.of(context)
.nativePushNamed('flutter2native', arguments: {}));
}),
TextButton(
child: Text('🍐: Navigator.of(context)?.pushNamed'),
child: const Text('🍐: Navigator.of(context)?.pushNamed'),
onPressed: () async {
_showResult(
context,
Expand All @@ -45,10 +48,10 @@ class _Flutter2NativePageState extends State<Flutter2NativePage> {
if (_result != null)
Text(
'result: $_result',
style: TextStyle(color: CupertinoColors.destructiveRed),
style: const TextStyle(color: CupertinoColors.destructiveRed),
),
Padding(
padding: const EdgeInsets.all(8.0),
const Padding(
padding: EdgeInsets.all(8.0),
child: Text('''推荐使用🍎来打开native路由
注意事项
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _Native2FlutterPageState extends State<Native2FlutterPage> {
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
navigationBar: const CupertinoNavigationBar(
middle: Text('Native2Flutter'),
),
child: SafeArea(
Expand All @@ -29,7 +29,7 @@ class _Native2FlutterPageState extends State<Native2FlutterPage> {
children: [
Text(widget.date ?? 'No Date'),
TextButton(
child: Text('带参数返回'),
child: const Text('带参数返回'),
onPressed: () =>
Navigator.of(context).pop('Result From Flutter'),
),
Expand Down
4 changes: 3 additions & 1 deletion example/lib/src/pages/features/basic/pages/tab_page.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import 'package:flutter/material.dart';

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

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

class _TabPageState extends State<TabPage> {
@override
Widget build(BuildContext context) {
return Center(
return const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand Down
21 changes: 12 additions & 9 deletions example/lib/src/pages/features/basic/pages/transparent_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

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

@override
_TransparentPageState createState() => _TransparentPageState();
}
Expand All @@ -23,12 +25,14 @@ class _TransparentPageState extends State<TransparentPage>

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
return PopScope(
canPop: false,
onPopInvoked: (didPop) async {
if (didPop) return;
await showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('这里可以拦截返回'),
title: const Text('这里可以拦截返回'),
actions: [
CupertinoActionSheetAction(
onPressed: () {
Expand All @@ -39,18 +43,17 @@ class _TransparentPageState extends State<TransparentPage>
Navigator.of(context).pop(true);
});
},
child: Text('返回'),
child: const Text('返回'),
)
],
));
return Future.microtask(
() => Future.delayed(Duration(milliseconds: 300), () {
return true;
}));
Future.delayed(const Duration(milliseconds: 300), () {
Navigator.of(context).pop();
});
},
child: AnimatedOpacity(
opacity: _opacity,
duration: Duration(milliseconds: 200),
duration: const Duration(milliseconds: 200),
child: GestureDetector(
child: Container(
color: Colors.black,
Expand Down
Loading

0 comments on commit e1c233c

Please sign in to comment.