mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Migrate platform_channels to go_router (#1533)
* Migrate platform_channels to go_router
* code format
* move addPetDetails into a subroute of petListScreen
* code format
* refactor router and fix tests
* removed unused import
* Elide `web_dashboard` from Master CI (#1535)
* Bump ossf/scorecard-action from 2.1.0 to 2.1.1 (#1536)
Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.1.0 to 2.1.1.
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](937ffa90d7...15c10fcf1c)
---
updated-dependencies:
- dependency-name: ossf/scorecard-action
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* go_router 6.0.0
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Brett Morgan <brett.morgan@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:platform_channels/src/add_pet_details.dart';
|
import 'package:platform_channels/src/add_pet_details.dart';
|
||||||
import 'package:platform_channels/src/event_channel_demo.dart';
|
import 'package:platform_channels/src/event_channel_demo.dart';
|
||||||
import 'package:platform_channels/src/method_channel_demo.dart';
|
import 'package:platform_channels/src/method_channel_demo.dart';
|
||||||
@@ -18,25 +19,54 @@ class PlatformChannelSample extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp.router(
|
||||||
routes: {
|
|
||||||
'/methodChannelDemo': (context) => const MethodChannelDemo(),
|
|
||||||
'/eventChannelDemo': (context) => const EventChannelDemo(),
|
|
||||||
'/platformImageDemo': (context) => const PlatformImageDemo(),
|
|
||||||
'/petListScreen': (context) => const PetListScreen(),
|
|
||||||
'/addPetDetails': (context) => const AddPetDetails(),
|
|
||||||
},
|
|
||||||
title: 'Platform Channel Sample',
|
title: 'Platform Channel Sample',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
snackBarTheme: SnackBarThemeData(
|
snackBarTheme: SnackBarThemeData(
|
||||||
backgroundColor: Colors.blue[500],
|
backgroundColor: Colors.blue[500],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
home: const HomePage(),
|
routerConfig: router(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GoRouter router([String? initialLocation]) {
|
||||||
|
return GoRouter(
|
||||||
|
initialLocation: initialLocation ?? '/',
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: '/',
|
||||||
|
builder: (context, state) => const HomePage(),
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: 'methodChannelDemo',
|
||||||
|
builder: (context, state) => const MethodChannelDemo(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'eventChannelDemo',
|
||||||
|
builder: (context, state) => const EventChannelDemo(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'platformImageDemo',
|
||||||
|
builder: (context, state) => const PlatformImageDemo(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: 'petListScreen',
|
||||||
|
builder: (context, state) => const PetListScreen(),
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: 'addPetDetails',
|
||||||
|
builder: (context, state) => const AddPetDetails(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
class DemoInfo {
|
class DemoInfo {
|
||||||
final String demoTitle;
|
final String demoTitle;
|
||||||
final String demoRoute;
|
final String demoRoute;
|
||||||
@@ -90,7 +120,7 @@ class DemoTile extends StatelessWidget {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(demoInfo.demoTitle),
|
title: Text(demoInfo.demoTitle),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pushNamed(context, demoInfo.demoRoute);
|
context.go(demoInfo.demoRoute);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:platform_channels/src/pet_list_message_channel.dart';
|
import 'package:platform_channels/src/pet_list_message_channel.dart';
|
||||||
|
|
||||||
/// Demonstrates how to use [BasicMessageChannel] to send a message to platform.
|
/// Demonstrates how to use [BasicMessageChannel] to send a message to platform.
|
||||||
@@ -36,7 +37,7 @@ class _AddPetDetailsState extends State<AddPetDetails> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
Navigator.pop(context);
|
context.pop();
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:platform_channels/src/pet_list_message_channel.dart';
|
import 'package:platform_channels/src/pet_list_message_channel.dart';
|
||||||
|
|
||||||
/// Demonstrates how to use [BasicMessageChannel] to send & receive the platform
|
/// Demonstrates how to use [BasicMessageChannel] to send & receive the platform
|
||||||
@@ -52,7 +53,7 @@ class _PetListScreenState extends State<PetListScreen> {
|
|||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pushNamed(context, '/addPetDetails');
|
context.go('/petListScreen/addPetDetails');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
body: petListModel.petList.isEmpty
|
body: petListModel.petList.isEmpty
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
cupertino_icons: ^1.0.3
|
cupertino_icons: ^1.0.3
|
||||||
|
go_router: ^6.0.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:platform_channels/src/add_pet_details.dart';
|
import 'package:platform_channels/main.dart' as app;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('AddPetDetails tests', () {
|
group('AddPetDetails tests', () {
|
||||||
@@ -20,7 +20,12 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Enter pet details', (tester) async {
|
testWidgets('Enter pet details', (tester) async {
|
||||||
await tester.pumpWidget(const MaterialApp(home: AddPetDetails()));
|
var router = app.router('/petListScreen/addPetDetails');
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp.router(
|
||||||
|
routerConfig: router,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
// Enter the breed of cat.
|
// Enter the breed of cat.
|
||||||
await tester.enterText(find.byType(TextField), 'Persian');
|
await tester.enterText(find.byType(TextField), 'Persian');
|
||||||
@@ -33,6 +38,9 @@ void main() {
|
|||||||
|
|
||||||
expect(petList, isNotEmpty);
|
expect(petList, isNotEmpty);
|
||||||
expect(petList.last['breed'], 'Persian');
|
expect(petList.last['breed'], 'Persian');
|
||||||
|
|
||||||
|
// Navigate back to /petListScreen
|
||||||
|
expect(router.location, '/petListScreen/');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user