From 200b2509268aa6ed1844aacda65a4750d3d574ae Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Mon, 23 Sep 2019 20:33:27 +0800 Subject: [PATCH] fix: use common push route method for span link --- lib/utils/utils.dart | 21 ++++++++++----------- lib/widgets/event_item.dart | 12 +++++++----- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 3ff9969..e8508be 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -3,10 +3,12 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; +import 'package:git_touch/models/theme.dart'; import 'package:git_touch/screens/repository.dart'; import 'package:git_touch/screens/user.dart'; import 'package:intl/intl.dart'; import 'package:primer/primer.dart'; +import 'package:provider/provider.dart'; export 'package:flutter_vector_icons/flutter_vector_icons.dart'; final monospaceFont = Platform.isIOS ? 'Menlo' : 'monospace'; // FIXME: @@ -47,31 +49,28 @@ void nextTick(Function callback, [int milliseconds = 0]) { }); } -TextSpan createLinkSpan(BuildContext context, String text, Function handle) { +TextSpan createLinkSpan( + BuildContext context, + String text, + Widget Function(BuildContext) builder, +) { return TextSpan( text: text, style: TextStyle(color: PrimerColors.blue500, fontWeight: FontWeight.w600), recognizer: TapGestureRecognizer() ..onTap = () { - Navigator.of(context).push( - // FIXME: Material route - CupertinoPageRoute( - builder: (context) { - return handle(); - }, - ), - ); + Provider.of(context).pushRoute(context, builder); }, ); } TextSpan createUserSpan(BuildContext context, String login) { - return createLinkSpan(context, login, () => UserScreen(login)); + return createLinkSpan(context, login, (_) => UserScreen(login)); } TextSpan createRepoLinkSpan(BuildContext context, String owner, String name) { return createLinkSpan( - context, '$owner/$name', () => RepositoryScreen(owner, name)); + context, '$owner/$name', (_) => RepositoryScreen(owner, name)); } class Palette { diff --git a/lib/widgets/event_item.dart b/lib/widgets/event_item.dart index 3b03f45..d9ddfcc 100644 --- a/lib/widgets/event_item.dart +++ b/lib/widgets/event_item.dart @@ -43,13 +43,15 @@ class EventItem extends StatelessWidget { // var resource = isPullRequest ? 'pull_request' : 'issue'; // int number = event.payload['issue']['number']; - return createLinkSpan(context, '#' + number.toString(), () { - return IssueScreen.fromFullName( + return createLinkSpan( + context, + '#' + number.toString(), + (_) => IssueScreen.fromFullName( number: number, fullName: event.repoFullName, isPullRequest: isPullRequest, - ); - }); + ), + ); } Widget _buildItem({ @@ -98,7 +100,7 @@ class EventItem extends StatelessWidget { createLinkSpan( context, event.actorLogin, - () => UserScreen(event.actorLogin), + (_) => UserScreen(event.actorLogin), ), ...spans, ],