creek
The AI Image Editor of 2030git clone https://github.com/maydayv7/creek
lib/ui/pages/settings_page.dart (3840B)
1import 'package:flutter/material.dart';
2import 'package:shared_preferences/shared_preferences.dart';
3import 'package:creekui/ui/styles/variables.dart';
4import 'package:creekui/ui/pages/image_analysis_page.dart';
5import 'package:creekui/ui/widgets/primary_button.dart';
6import 'package:creekui/ui/widgets/app_bar.dart';
7import 'package:creekui/ui/widgets/text_field.dart';
8
9class SettingsPage extends StatefulWidget {
10 const SettingsPage({super.key});
11
12 @override
13 State<SettingsPage> createState() => _SettingsPageState();
14}
15
16class _SettingsPageState extends State<SettingsPage> {
17 final TextEditingController _nameController = TextEditingController();
18 bool _isLoading = true;
19 String _originalName = '';
20
21 @override
22 void initState() {
23 super.initState();
24 _loadUserData();
25 }
26
27 Future<void> _loadUserData() async {
28 final prefs = await SharedPreferences.getInstance();
29 String name = prefs.getString('user_name') ?? 'Alex';
30 if (name.trim().isEmpty) name = 'Alex';
31
32 setState(() {
33 _nameController.text = name;
34 _originalName = name;
35 _isLoading = false;
36 });
37 }
38
39 Future<void> _saveUserName() async {
40 final newName = _nameController.text.trim();
41 if (newName.isEmpty) return;
42 final prefs = await SharedPreferences.getInstance();
43 await prefs.setString('user_name', newName);
44 setState(() => _originalName = newName);
45 if (mounted) FocusScope.of(context).unfocus();
46 }
47
48 @override
49 void dispose() {
50 _nameController.dispose();
51 super.dispose();
52 }
53
54 @override
55 Widget build(BuildContext context) {
56 final bool hasChanges = _nameController.text.trim() != _originalName;
57 return Scaffold(
58 backgroundColor: Colors.white,
59 appBar: const CommonAppBar(title: "Settings"),
60 body:
61 _isLoading
62 ? const Center(child: CircularProgressIndicator())
63 : Padding(
64 padding: const EdgeInsets.all(24.0),
65 child: Column(
66 crossAxisAlignment: CrossAxisAlignment.start,
67 children: [
68 const Text(
69 "Profile Settings",
70 style: TextStyle(
71 fontFamily: 'GeneralSans',
72 fontSize: 18,
73 fontWeight: FontWeight.w600,
74 color: Variables.textPrimary,
75 ),
76 ),
77 const SizedBox(height: 16),
78 CommonTextField(
79 label: "Your Name",
80 hintText: "Enter your name",
81 controller: _nameController,
82 onChanged: (val) => setState(() {}),
83 suffixIcon:
84 hasChanges
85 ? IconButton(
86 icon: const Icon(
87 Icons.check,
88 color: Variables.textPrimary,
89 ),
90 onPressed: _saveUserName,
91 tooltip: 'Save Name',
92 )
93 : null,
94 ),
95 const Spacer(),
96
97 // Test Analysis
98 PrimaryButton(
99 text: "Test Image Analysis",
100 onPressed: () {
101 Navigator.push(
102 context,
103 MaterialPageRoute(
104 builder: (_) => const ImageAnalysisPage(),
105 ),
106 );
107 },
108 ),
109 const SizedBox(height: 20),
110 ],
111 ),
112 ),
113 );
114 }
115}