Browse Source

Country select with hard coded default instances

master
Robby Zambito 6 months ago
parent
commit
f3a562b35c
7 changed files with 206 additions and 30 deletions
  1. +35
    -0
      lib/data/instance.dart
  2. +4
    -0
      lib/main.dart
  3. +14
    -22
      lib/views/unauthenticated/auth_screen.dart
  4. +108
    -8
      lib/views/unauthenticated/instance_selector.dart
  5. +33
    -0
      lib/views/unauthenticated/login.dart
  6. +0
    -0
      lib/views/unauthenticated/register.dart
  7. +12
    -0
      lib/views/unauthenticated/sign_up.dart

+ 35
- 0
lib/data/instance.dart View File

@ -0,0 +1,35 @@
// 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:country_codes/country_codes.dart';
abstract class Instance {
String get url;
}
// HamletInstance of a Hamlet server
class HamletInstance implements Instance {
final String city;
final String state;
final CountryDetails country;
HamletInstance({this.city, this.state, this.country});
String get url => "https://"
"${city.toLowerCase()}." +
state != null ? "${state.toLowerCase()}." : "" +
"${country.alpha3Code.toLowerCase()}." +
"hamlet.social";
}

+ 4
- 0
lib/main.dart View File

@ -13,6 +13,7 @@
// 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:country_codes/country_codes.dart';
import 'package:flutter/material.dart';
import 'package:hamlet_social/views/authenticated/timeline_screen.dart';
import 'package:hamlet_social/views/unauthenticated/auth_screen.dart';
@ -23,6 +24,7 @@ import 'package:web_socket_channel/io.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await CountryCodes.init();
Pleroma pleroma = Pleroma(
Uri.parse("https://zoinks.one"),
@ -77,6 +79,8 @@ class MyApp extends StatelessWidget {
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: '/',
routes: {},
home: bloc.account.value == null
? AuthScreen()
: TimelineScreen(account: bloc.account.value),

+ 14
- 22
lib/views/unauthenticated/auth_screen.dart View File

@ -22,8 +22,10 @@ import 'package:pleroma_flutter/pleroma_flutter.dart';
import 'package:pleroma_dart/pleroma_dart.dart';
import 'package:provider/provider.dart';
class AuthScreen extends StatefulWidget {
import 'login.dart';
import 'sign_up.dart';
class AuthScreen extends StatefulWidget {
AuthScreen({Key key}) : super(key: key);
@override
@ -33,13 +35,14 @@ class AuthScreen extends StatefulWidget {
class _AuthScreenState extends State<AuthScreen> {
AuthBloc bloc;
var _isSignUp = true;
final _authBuilderKey = GlobalKey<AuthBuilderState>();
void _onLogin(Account account) {
scheduleMicrotask(() {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => TimelineScreen(account: account))
);
MaterialPageRoute(builder: (_) => TimelineScreen(account: account)));
});
}
@ -55,6 +58,12 @@ class _AuthScreenState extends State {
super.dispose();
}
void _toggleSignup() {
setState(() {
this._isSignUp = !this._isSignUp;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -65,25 +74,8 @@ class _AuthScreenState extends State {
key: _authBuilderKey,
bloc: bloc,
onLogin: _onLogin,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(50,30,0,0),
child: Text("Sign Up"),
),
Padding(
padding: EdgeInsets.fromLTRB(50,30,0,0),
child: InstanceSelector(),
),
Padding(
padding: EdgeInsets.fromLTRB(50,30,0,0),
child: Text("Sign In"),
),
],
),
child: !_isSignUp ? SignUpForm() : LoginForm(),
),
);
}
}
}

+ 108
- 8
lib/views/unauthenticated/instance_selector.dart View File

@ -13,7 +13,12 @@
// 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 'dart:developer';
import 'package:flutter/material.dart';
import 'package:direct_select/direct_select.dart';
import 'package:hamlet_social/data/instance.dart';
import 'package:country_codes/country_codes.dart';
class InstanceSelector extends StatefulWidget {
@override
@ -21,17 +26,112 @@ class InstanceSelector extends StatefulWidget {
}
class _InstanceSelectorState extends State<InstanceSelector> {
var _isCustomInstance = false;
final _formKey = GlobalKey<FormState>();
final List<HamletInstance> _hamletInstanceList = [
HamletInstance(
city: "Cazenovia",
state: "New York",
country: CountryCodes.detailsForLocale(Locale('en', 'US'))),
HamletInstance(
city: "Syracuse",
state: "New York",
country: CountryCodes.detailsForLocale(Locale('en', 'US'))),
HamletInstance(
city: "Berlin",
country: CountryCodes.detailsForLocale(Locale('de', 'DE'))),
// "United States of America",
// "Canada",
// "Germany",
// "Spain",
// "Italy",
];
List<Widget> _buildCountryList() {
final res = _hamletInstanceList
.map((i) => i.country.localizedName)
.toSet()
.toList();
res.sort();
return res.map((c) => Text(c)).toList();
}
int _selectedCountryIndex = 0;
void _toggleIsCustomInstance() {
this.setState(() {
_isCustomInstance = !_isCustomInstance;
});
}
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text("Country"),
Text("State"),
Text("City"),
],
return Center(
child: Column(
children: <Widget>[
_isCustomInstance
? Column(
children: [
Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Text("Country"),
),
DirectSelect(
itemExtent: 35,
selectedIndex: _selectedCountryIndex,
child: _buildCountryList()[_selectedCountryIndex],
onSelectedItemChanged: (index) {
setState(() {
_selectedCountryIndex = index;
});
},
items: _buildCountryList(),
),
],
)
: Column(
children: <Widget>[TextFormField()],
),
GestureDetector(
onTap: this._toggleIsCustomInstance,
child: Text(_isCustomInstance
? "Login to a Hamlet instance instead"
: "Login to a custom instance instead"),
),
],
),
);
}
}
// class _CountryFormField extends FormField<String> {
// _CountryFormField({
// Key key,
// String initialValue = "United States of America",
// this.decoration = const InputDecoration(),
// onSaved,
// validator,
// this.onChanged,
// this.constraints = const BoxConstraints(),
// }) : assert(decoration != null),
// assert(initialValue != null),
// assert(constraints != null),
// super(
// key: key,
// onSaved: onSaved,
// initialValue: initialValue,
// validator: validator,
// builder: (FormFieldState field) {});
// final ValueChanged onChanged;
// final InputDecoration decoration;
// final BoxConstraints constraints;
// }
// class _StateFormField extends FormField<String> {}
}
// class _CityFormField extends FormField<String> {}

+ 33
- 0
lib/views/unauthenticated/login.dart View File

@ -0,0 +1,33 @@
// 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/instance_selector.dart';
// This should probably just redirect the user to the login
// page of the instance in an embeded web page
class LoginForm extends StatefulWidget {
@override
_LoginFormState createState() => _LoginFormState();
}
class _LoginFormState extends State<LoginForm> {
var _isInstanceSelected = false;
@override
Widget build(BuildContext context) {
return !_isInstanceSelected ? InstanceSelector() : Text("Instance selected");
}
}

+ 0
- 0
lib/views/unauthenticated/register.dart View File


+ 12
- 0
lib/views/unauthenticated/sign_up.dart View File

@ -0,0 +1,12 @@
import 'package:flutter/material.dart';
class SignUpForm extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
throw UnimplementedError();
}
}

Loading…
Cancel
Save