flutter time babey
This commit is contained in:
commit
98798fa14f
134 changed files with 4587 additions and 0 deletions
1
lib/api/oauth.dart
Normal file
1
lib/api/oauth.dart
Normal file
|
@ -0,0 +1 @@
|
|||
import 'package:http/http.dart' as http;
|
21
lib/api/user.dart
Normal file
21
lib/api/user.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
bool isValidUsername({required String name}) {
|
||||
if (name.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
return RegExp(r".+\@.+\..+").hasMatch(cleanUpUsername(name: name));
|
||||
}
|
||||
|
||||
String cleanUpUsername({required String name}) {
|
||||
name = name.replaceAll(" ", "");
|
||||
if (name.isNotEmpty) {
|
||||
if (name[0] == "@") {
|
||||
name = name.substring(1);
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
Uri urlFromUsername({required String name}) {
|
||||
name = cleanUpUsername(name: name);
|
||||
return Uri.parse("https://${name.substring(name.indexOf("@") + 1)}");
|
||||
}
|
11
lib/main.dart
Normal file
11
lib/main.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:slothmu/partials/main_scaffold.dart';
|
||||
import 'pages/login.dart';
|
||||
|
||||
void main() => runApp(MaterialApp(
|
||||
initialRoute: '/login',
|
||||
routes: {
|
||||
'/': (context) => const MainScaffold(),
|
||||
'/login': (context) => const Login(),
|
||||
},
|
||||
));
|
5
lib/pages/chat/ chat.dart
Normal file
5
lib/pages/chat/ chat.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
|
||||
Widget Chat() {
|
||||
return Center(child: Text("Chat"));
|
||||
}
|
70
lib/pages/login.dart
Normal file
70
lib/pages/login.dart
Normal file
|
@ -0,0 +1,70 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:slothmu/api/user.dart';
|
||||
|
||||
class Login extends StatefulWidget {
|
||||
const Login({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Login> createState() => _LoginState();
|
||||
}
|
||||
|
||||
class _LoginState extends State<Login> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Scaffold(
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: LoginForm(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LoginForm extends StatefulWidget {
|
||||
const LoginForm({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LoginForm> createState() => _LoginFormState();
|
||||
}
|
||||
|
||||
class _LoginFormState extends State<LoginForm> {
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
onChanged: () {
|
||||
formKey.currentState!.validate();
|
||||
},
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
const Text("Welcome!", style: TextStyle(fontSize: 64)),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: "user id",
|
||||
hintText: "user@example.com",
|
||||
icon: Icon(Icons.person),
|
||||
prefixText: "@",
|
||||
),
|
||||
autofocus: true,
|
||||
validator: (value) {
|
||||
if (value!.isEmpty || !isValidUsername(name: value)) {
|
||||
return "Sorry, this user id doesn't look quite right...";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
final isValid = formKey.currentState!.validate();
|
||||
},
|
||||
icon: Icon(Icons.login),
|
||||
label: Text("authorize in browser"))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
15
lib/pages/settings/settings.dart
Normal file
15
lib/pages/settings/settings.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
|
||||
Widget Settings() {
|
||||
return SafeArea(
|
||||
child: SettingsList(contentPadding: EdgeInsets.all(24), sections: [
|
||||
SettingsSection(title: Text("General"), tiles: [
|
||||
SettingsTile(
|
||||
title: Text("Language"),
|
||||
value: Text("no"),
|
||||
)
|
||||
])
|
||||
]),
|
||||
);
|
||||
}
|
5
lib/pages/timeline/timeline.dart
Normal file
5
lib/pages/timeline/timeline.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget Timeline() {
|
||||
return Center(child: Text("Home"));
|
||||
}
|
40
lib/partials/main_scaffold.dart
Normal file
40
lib/partials/main_scaffold.dart
Normal file
|
@ -0,0 +1,40 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:slothmu/pages/chat/%20chat.dart';
|
||||
import 'package:slothmu/pages/timeline/timeline.dart';
|
||||
import 'package:slothmu/pages/settings/settings.dart';
|
||||
|
||||
class MainScaffold extends StatefulWidget {
|
||||
const MainScaffold({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MainScaffold> createState() => _MainScaffoldState();
|
||||
}
|
||||
|
||||
class _MainScaffoldState extends State<MainScaffold> {
|
||||
int index = 0;
|
||||
final screens = [
|
||||
Timeline(),
|
||||
Chat(),
|
||||
Settings(),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: screens[index],
|
||||
bottomNavigationBar: NavigationBar(
|
||||
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
|
||||
elevation: 0,
|
||||
height: 60,
|
||||
onDestinationSelected: (index) => setState(() => this.index = index),
|
||||
selectedIndex: index,
|
||||
destinations: const [
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.list_alt), label: "Timeline"),
|
||||
NavigationDestination(icon: Icon(Icons.chat), label: "Chat"),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.settings), label: "Settings"),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue