Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ LinXunFeng <[email protected]>
Hashir Shoaib <[email protected]>
Ricardo Dalarme <[email protected]>
Andrei Kabylin <[email protected]>
Ernesto Ramirez <[email protected]>
7 changes: 6 additions & 1 deletion packages/go_router_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## 4.1.0

- Adds support for classes that support fromJson/toJson. [#117261](https://github.com/flutter/flutter/issues/117261)
- Adds annotation that enable custom string encoder/decoder [#110781](https://github.com/flutter/flutter/issues/110781)

## 4.0.1

- Fixes unnecessary whitespace in generated `RelativeGoRouteData`.
- Fixes unnecessary whitespace in generated `RelativeGoRouteData`.

## 4.0.0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs, unreachable_from_main

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

part 'custom_encoder_example.g.dart';

void main() => runApp(App());

class App extends StatelessWidget {
App({super.key});

@override
Widget build(BuildContext context) =>
MaterialApp.router(routerConfig: _router, title: _appTitle);

final GoRouter _router = GoRouter(routes: $appRoutes);
}

@TypedGoRoute<HomeRoute>(
path: '/',
name: 'Home',
routes: <TypedGoRoute<GoRouteData>>[
TypedGoRoute<EncodedRoute>(path: 'encoded'),
],
)
class HomeRoute extends GoRouteData with $HomeRoute {
const HomeRoute();

@override
Widget build(BuildContext context, GoRouterState state) => const HomeScreen();
}

class EncodedRoute extends GoRouteData with $EncodedRoute {
const EncodedRoute(this.token);

@CustomParameterCodec(encode: toBase64, decode: fromBase64)
final String token;

@override
Widget build(BuildContext context, GoRouterState state) =>
EncodedScreen(token: token);
}

class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text(_appTitle)),
body: ListView(
children: <Widget>[
ListTile(
title: const Text('Base64Token'),
onTap: () => const EncodedRoute('Base64Token').go(context),
),
ListTile(
title: const Text('from url only'),
// like in deep links
onTap: () => context.go('/encoded?token=ZW5jb2RlZCBpbmZvIQ'),
),
],
),
);
}

class EncodedScreen extends StatelessWidget {
const EncodedScreen({super.key, required this.token});
final String token;

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text('Base64Token')),
body: Center(child: Text(token)),
);
}

String fromBase64(String value) {
return const Utf8Decoder().convert(
base64Url.decode(base64Url.normalize(value)),
);
}

String toBase64(String value) {
return base64Url.encode(const Utf8Encoder().convert(value));
}

const String _appTitle = 'GoRouter Example: custom encoder';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions packages/go_router_builder/example/lib/json_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs, unreachable_from_main

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import 'shared/json_example.dart';

part 'json_example.g.dart';

void main() => runApp(App());

class App extends StatelessWidget {
App({super.key});

@override
Widget build(BuildContext context) =>
MaterialApp.router(routerConfig: _router, title: _appTitle);

final GoRouter _router = GoRouter(routes: $appRoutes);
}

@TypedGoRoute<HomeRoute>(
path: '/',
name: 'Home',
routes: <TypedGoRoute<GoRouteData>>[TypedGoRoute<JsonRoute>(path: 'json')],
)
class HomeRoute extends GoRouteData with $HomeRoute {
const HomeRoute();

@override
Widget build(BuildContext context, GoRouterState state) => const HomeScreen();
}

class JsonRoute extends GoRouteData with $JsonRoute {
const JsonRoute(this.json);

final JsonExample json;

@override
Widget build(BuildContext context, GoRouterState state) =>
JsonScreen(json: json);
}

class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: const Text(_appTitle)),
body: ListView(
children: <Widget>[
for (final JsonExample json in jsonData)
ListTile(
title: Text(json.name),
onTap: () => JsonRoute(json).go(context),
),
],
),
);
}

class JsonScreen extends StatelessWidget {
const JsonScreen({required this.json, super.key});
final JsonExample json;

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(title: Text(json.name)),
body: ListView(
key: ValueKey<String>(json.id),
children: <Widget>[Text(json.id), Text(json.name)],
),
);
}

const String _appTitle = 'GoRouter Example: builder';
65 changes: 65 additions & 0 deletions packages/go_router_builder/example/lib/json_example.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading