reinitialising project

This commit is contained in:
2025-05-03 03:44:06 +01:00
parent f72ea71bfd
commit 2033ad79e2
16 changed files with 851 additions and 202 deletions
+29
View File
@@ -0,0 +1,29 @@
import 'package:nextcloud/nextcloud.dart';
import 'package:nextcloud/provisioning_api.dart';
Future<String> login(String uri, String username, String password) async {
try {
final client = NextcloudClient(
Uri.parse(uri),
loginName: username,
password: password,
);
final response =
await client.provisioningApi.users.getUser(userId: username);
if (response.statusCode == 200) {
print(response.body);
return "successful|$response.body.ocs.data.";
} else {
return "failed|$response.body.ocs.data";
}
} catch (e) {
print("");
print("$e");
print("");
return "$e";
}
}
+54
View File
@@ -0,0 +1,54 @@
// import 'package:nextcloud/nextcloud.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/material.dart';
// import 'package:http/http.dart' as http;
const primaryColor = Color.fromARGB(255, 26, 26, 74);
const primaryLightColor = Color.fromARGB(150, 238, 224, 173);
const double defaultPadding = 15.0;
const timeout = 3;
// var client = http.Client();
// var client = NextcloudClient()
setSharedPref(String key, var value) async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
switch (value.runtimeType.toString()) {
case 'String':
sharedPreferences.setString(key, value);
break;
case 'double':
sharedPreferences.setDouble(key, value);
break;
case 'int':
sharedPreferences.setInt(key, value);
break;
case 'bool':
sharedPreferences.setBool(key, value);
break;
}
}
getSharedPref(var key, var type) async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
switch (type) {
case 'String':
return sharedPreferences.getString(key);
case 'double':
return sharedPreferences.getDouble(key);
case 'int':
return sharedPreferences.getInt(key);
case 'bool':
return sharedPreferences.getBool(key);
}
}
+32 -109
View File
@@ -1,8 +1,10 @@
import 'package:flutter/material.dart';
import 'package:nextcloudapp/components/default_values.dart';
import 'package:nextcloudapp/screens/login_screen.dart';
void main() {
runApp(const MyApp());
}
void main() => runApp(
const MyApp(),
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@@ -11,115 +13,36 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
title: 'Nextcloud',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
primaryColor: primaryColor,
scaffoldBackgroundColor: Colors.white,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
elevation: 0,
foregroundColor: Colors.white,
backgroundColor: primaryColor,
shape: const StadiumBorder(),
maximumSize: const Size(double.infinity, 56),
minimumSize: const Size(double.infinity, 56),
),
),
inputDecorationTheme: const InputDecorationTheme(
filled: true,
fillColor: primaryLightColor,
iconColor: primaryColor,
prefixIconColor: primaryColor,
contentPadding: EdgeInsets.symmetric(
horizontal: defaultPadding, vertical: defaultPadding),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(30)),
borderSide: BorderSide.none,
),
),
fontFamily: 'Poppins',
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
home: const LoginScreen(),
);
}
}
+196
View File
@@ -0,0 +1,196 @@
import 'package:flutter/material.dart';
import 'package:nextcloudapp/api/login_api.dart';
import 'package:nextcloudapp/components/default_values.dart';
import 'package:nextcloudapp/screens/welcome_screen.dart';
import 'package:nextcloudapp/service/snackbar_service.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
var _deviceHeight;
var _deviceWidth;
var urlController;
var usernameController;
var passwordController;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
var checked = false;
var obscureText = true;
@override
Widget build(BuildContext context) {
SnackBarService.instance.buildContext = context;
_deviceHeight = MediaQuery.of(context).size.height;
_deviceWidth = MediaQuery.of(context).size.width;
return Scaffold(
body: Align(
child: Container(
height: _deviceHeight * 0.60,
padding: EdgeInsets.symmetric(horizontal: _deviceWidth * 0.05),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_inputField(),
_passwordSaveField(),
_signInField(),
],
),
),
),
);
}
Widget _inputField() {
return SizedBox(
height: _deviceHeight * 0.25,
child: Form(
key: _formKey,
onChanged: () {
_formKey.currentState?.save();
},
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
keyboardType: TextInputType.url,
textInputAction: TextInputAction.next,
cursorColor: Colors.white,
style: TextStyle(
color: Colors.black,
),
onSaved: (_input) {
setState(() {
urlController = _input!;
});
},
validator: (_input) {
return null;
},
decoration: const InputDecoration(
hintText: "hosting URL",
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)
),
prefixIcon: Padding(
padding: EdgeInsets.all(defaultPadding),
child: Icon(Icons.computer_outlined),
),
),
),
TextFormField(
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
style: TextStyle(
color: Colors.black,
),
onSaved: (_input) {
setState(() {
usernameController = _input!;
});
},
decoration: const InputDecoration(
hintText: "username",
prefixIcon: Padding(
padding: EdgeInsets.all(defaultPadding),
child: Icon(Icons.person),
),
),
),
TextFormField(
keyboardType: TextInputType.visiblePassword,
textInputAction: TextInputAction.done,
obscureText: obscureText,
onSaved: (_input) {
setState(() {
passwordController = _input!;
});
},
cursorColor: primaryColor,
decoration: InputDecoration(
hintText: "Password",
prefixIcon: const Padding(
padding: EdgeInsets.all(defaultPadding),
child: Icon(Icons.lock),
),
suffixIcon: IconButton(
icon: Icon(
obscureText ? Icons.visibility : Icons.visibility_off),
onPressed: () {
setState(
() {
obscureText = !obscureText;
},
);
},
)),
),
],
),
),
);
}
Widget _passwordSaveField() {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Checkbox(
value: checked,
onChanged: (value) {
setState(() {
checked = value!;
});
}),
const Text('Save Password'),
],
);
}
Widget _signInField() {
return ElevatedButton(
onPressed: () {
login(urlController.value.text, usernameController.value.text,
passwordController.value.text)
.then((
status,
) {
if (status.startsWith('successful')) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return const WelcomeScreen();
},
),
);
SnackBarService.instance.showSnackBarSuccess(status);
} else {
SnackBarService.instance.showSnackBarError(status);
}
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"sign in".toUpperCase(),
),
const SizedBox(width: 10),
const Icon(Icons.login)
],
),
);
}
}
View File
+27
View File
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
class WelcomeScreen extends StatefulWidget {
const WelcomeScreen({super.key});
@override
State<WelcomeScreen> createState() => _WelcomeScreenState();
}
class _WelcomeScreenState extends State<WelcomeScreen> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return const Scaffold(
body: Column(
children: [
],
),
);
}
}
+29
View File
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
class NavigationService {
//
static NavigationService instance = NavigationService();
GlobalKey<NavigatorState>? navigatorKey;
NavigationService() {
navigatorKey = GlobalKey<NavigatorState>();
}
Future<dynamic>? navigateToReplacement(String _routeName) {
return navigatorKey!.currentState!.pushReplacementNamed(_routeName);
}
Future<dynamic>? navigateTo(String _routeName) {
return navigatorKey!.currentState!.pushNamed(_routeName);
}
Future<dynamic>? navigateToRoute(MaterialPageRoute _route) {
return navigatorKey!.currentState!.push(_route);
}
// Manually Call Function
void goBack() {
return navigatorKey!.currentState!.pop();
}
}
+44
View File
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
class SnackBarService {
//
BuildContext? _buildContext;
static SnackBarService instance = SnackBarService();
set buildContext(BuildContext _context) {
_buildContext = _context;
}
void showSnackBarError(String _message) {
ScaffoldMessenger.of(_buildContext!).showSnackBar(
SnackBar(
duration: Duration(seconds: 2),
content: Text(
_message,
style: TextStyle(
color: Colors.white,
fontSize: 15,
),
),
backgroundColor: Colors.red,
),
);
}
void showSnackBarSuccess(String _message) {
ScaffoldMessenger.of(_buildContext!).showSnackBar(
SnackBar(
duration: Duration(seconds: 2),
content: Text(
_message,
style: TextStyle(
color: Colors.white,
fontSize: 15,
),
),
backgroundColor: Colors.green,
),
);
}
}