Browse Source

Broke route generation into its own class. Created a welcome screen.

master
Robby Zambito 6 months ago
parent
commit
aedc434528
4 changed files with 113 additions and 11 deletions
  1. +28
    -9
      lib/main.dart
  2. +42
    -0
      lib/route_generator.dart
  3. +2
    -2
      lib/views/unauthenticated/instance_selector.dart
  4. +41
    -0
      lib/views/unauthenticated/welcome_screen.dart

+ 28
- 9
lib/main.dart View File

@ -17,6 +17,7 @@ import 'package:country_codes/country_codes.dart';
import 'package:flutter/material.dart';
import 'package:hamlet_social/data/instance.dart';
import 'package:hamlet_social/endpoints/unauthenticated/available_instances.dart';
import 'package:hamlet_social/route_generator.dart';
import 'package:hamlet_social/views/authenticated/timeline_screen.dart';
import 'package:hamlet_social/views/unauthenticated/auth_screen.dart';
import 'package:pleroma_dart/pleroma_dart.dart';
@ -41,10 +42,10 @@ Future main() async {
await authBloc.initalized;
List<HamletInstance> hamletInstances = await availableInstances();
runApp(MyApp(
bloc: authBloc, pleroma: pleroma, hamletInstances: hamletInstances));
bloc: authBloc,
pleroma: pleroma,
hamletInstances: await availableInstances()));
}
class MyApp extends StatelessWidget {
@ -62,8 +63,9 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MultiProvider(
providers: [
Provider<AuthBloc>.value(value: bloc),
Provider<Pleroma>.value(value: pleroma),
Provider<AuthBloc>(create: (_) => bloc),
Provider<Pleroma>(create: (_) => pleroma),
Provider<List<HamletInstance>>(create: (_) => hamletInstances),
],
child: MaterialApp(
title: 'Hamlet',
@ -85,14 +87,31 @@ class MyApp extends StatelessWidget {
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: '/',
routes: {},
home: bloc.account.value == null
? AuthScreen(hamletInstances: hamletInstances)
: TimelineScreen(account: bloc.account.value),
onGenerateRoute: RouteGenerator.generateRoute,
// routes: {
// '/': (context) =>
// },
// home: Navigator(
// pages: [
// MaterialPage(
// child: AuthScreen(hamletInstances: widget.hamletInstances)),
// ],
// onPopPage: (route, result) {
// if (!route.didPop(result)) return false;
// return true;
// },
// ),
// home: bloc.account.value == null
// ? AuthScreen(hamletInstances: hamletInstances)
// : TimelineScreen(account: bloc.account.value),
),
);
}
// @override
// _MyAppState createState() => _MyAppState();
}
// class _MyAppState extends State<MyApp> {}
//
// class MyHomePage extends StatefulWidget {
// MyHomePage({

+ 42
- 0
lib/route_generator.dart View File

@ -0,0 +1,42 @@
// This file is part of Hamlet Social.
//
// Hamlet Social is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Hamlet Social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Hamlet Social. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart';
import 'package:hamlet_social/views/unauthenticated/auth_screen.dart';
import 'views/unauthenticated/welcome_screen.dart';
class RouteGenerator {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case '/':
return MaterialPageRoute(builder: (_) => WelcomeScreen());
case '/auth':
return MaterialPageRoute(builder: (_) => AuthScreen());
default:
return _errorRoute();
}
}
static Route<dynamic> _errorRoute() {
return MaterialPageRoute(
builder: (_) => Scaffold(
appBar: AppBar(title: Text('Error')),
body: Center(child: Text('Error')),
));
}
}

+ 2
- 2
lib/views/unauthenticated/instance_selector.dart View File

@ -178,8 +178,8 @@ class _InstanceSelectorState extends State {
child: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(_isCustomInstance
? "Login to a Hamlet instance instead"
: "Login to a custom instance instead"),
? "Connect to a Hamlet instance instead"
: "Connect to a custom instance instead"),
),
),
],

+ 41
- 0
lib/views/unauthenticated/welcome_screen.dart View File

@ -0,0 +1,41 @@
// This file is part of Hamlet Social.
//
// Hamlet Social is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// Hamlet Social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Hamlet Social. If not, see <https://www.gnu.org/licenses/>.
import 'package:flutter/material.dart';
import 'package:hamlet_social/data/instance.dart';
import 'package:hamlet_social/views/unauthenticated/instance_selector.dart';
import 'package:hamlet_social/views/unauthenticated/sign_up.dart';
import 'package:provider/provider.dart';
class WelcomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<HamletInstance> hamletInstances =
context.watch<List<HamletInstance>>();
return Scaffold(
appBar: AppBar(
title: const Text('Hamlet'),
),
body: Flex(
children: <Widget>[
Title(child: Text('Welcome to Hamlet!'), color: Colors.black),
InstanceSelector(hamletInstances),
],
direction: Axis.vertical,
),
);
}
}

Loading…
Cancel
Save